I've got alot of pages that will be going live on a site soon, and all have .php extentions. I heard it's possible to permanently redirect(301) away from the .php links... anyone know how to do this, or where to get some info? basically I would like the urls shortened from: www.site.com/page.php to www.site.com/page (with no .html, .php, or any extension at the end) thanks guys...
I think it is better to use mod_rewrite for this problem: RewriteEngine on RewriteRule ^/page /page.php [PT] or even more simple: RewriteEngine on RewriteRule ^/(.+) /$1.php [PT] but it will work only with urls such www.site.com/page To redirect user to a proper page from .php you can add this code in your php files: <?php $uri = str_replace(".php", "", getenv("REQUEST_URI")); header("HTTP/1.1 301 Moved Permanently"); header("Location: $uri"); ?>
All my .php files aren't online yet, so there's no PR or links yet... will the mod-rewrite from .php to no-.php be treated as a 301(perm) redirect for all future linkbuilding?
no, it helps only to associate "/page" and "/page.php". If there are no links to "page.php", everything is ok. 301 is using for moved pages only and your should use only links without ".php" and google and etc will not know about this pages. Your can add my code to prevent using ".php".
ANick, that will also append .php to CSS, JS, images and any other files! This works, and also stops duplicate content penalties by disabling access by 301 redirecting .php -> non .php RewriteEngine on # 301 redirect .php -> non .php RewriteCond %{REQUEST_URI} ^(.+)\.php$ [NC] RewriteRule . %1 [R=301,L] # Rewrite non .php -> .php ("transparent") RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ $1.php [L] Code (markup):