Redirecting portal.php to domain name with htaccess

Discussions about Apache mod Rewrite, .htaccess, Use, experiences ... URL Rewriting.

Moderator: Moderators

Redirecting portal.php to domain name with htaccess

Postby 993ti » Wed Oct 04, 2006 1:49 pm

My site is using a portal and uses this code in htaccess so when going to the domain, it goes to the portal:
Code: Select all
DirectoryIndex portal.php index.php index.html

It doesn't show portal.php in the url so that's good.
I'm not linking to portal.php anywhere since that code already takes care of that and instead every link to the homepage goes to the domain.
But, you can still use domain.com/portal.php.
Recently i checked if portal.php has any PR and it does (PR2).
How can i use htaccess so that PR isn't transferred to portal.php but to my domain (without creating a loop)?
993ti
 
Posts: 16
Joined: Sat Aug 26, 2006 6:25 pm

Advertisement

Postby dcz » Wed Oct 04, 2006 9:03 pm

Adsense ?

That's one thing to know with AdSense, Google is grabbing URLs from there and that's why for example some end up finding Google trying to load private URLs.

The redirection you're talking about is on the top of my TODO list :lol:, it's rather easy to implement it directly in the php files so I never really bother about doing it through .htaccess, but it could en up being a little faster so why not.

Till then, you could put this in your portal.php file :
Code: Select all
$uri = $_SERVER['REQUEST_URI'];
if (strpos($uri, "portal.php") && !strpos($uri, "?") {
   header(Status: 301 Moved Permanently, FALSE, 301);
   header("Location: "http://www.example.com/");
}


The strpos are used for velocity.

Now this code would be better if you add :
Code: Select all
   @session_write_close();
   @session_start();

before the first header() if you are using php sessions, and, as it could be the case, a little :
Code: Select all
   if ( !empty($db) ) {
      $db->sql_close();
   }

right after the php sessions close line if your file is using phpbb sessions ;)

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21238
Joined: Fri Apr 28, 2006 9:03 pm


Return to Apache mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 1 guest