mod rewrite - Redirect /about to /about.php in .htaccess -
first of all, know there plenty of similar questions around, but
- none of them seem work me
- none of them address want
what want is, title suggests, redirect urls without .php
extension actual .php
file - changing url if possible (which presume handled [r=301]). latest thing tried this:
rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewritecond %{request_filename} !-l rewriterule ^(.+)$ $1.php [r=301]
that doesn't work. can still cant access /about.php
/about
. (.htaccess rules working fine though)
i understand regex fine, htaccess rules mess head =[
so should do?
now know you're thinking
one of this: "why want this? rid of extensions , access pages via /about
or /about/
trailing slash."
i'd that, looks quite good. problem seo - assume page ranks annihilated because of sudden they're on different urls. before suggest that, suggest how i'd keep page ranks first.
what i'm doing url shortening poster - it's lot easier people remember mywebsite.com/about
mywebsite.com/about.php
.
enable mod_rewrite , .htaccess through httpd.conf
, put code in .htaccess
under document_root
directory:
options +followsymlinks -multiviews # turn mod_rewrite on rewriteengine on rewritebase / ## hide .php extension # externally redirect /dir/foo.php /dir/foo rewritecond %{the_request} ^[a-z]{3,}\s([^.]+)\.php [nc] rewriterule ^ %1 [r=302,l] # internally forward /dir/foo/ /dir/foo.php rewritecond %{request_filename} !-d rewritecond %{document_root}/$1.php -f rewriterule ^(.*?)/?$ $1.php [l]
please make sure have multiviews options disabled using: options -multiviews
once verify working fine, replace r=302
r=301
. avoid using r=301
(permanent redirect) while testing mod_rewrite rules.
Comments
Post a Comment