Forum Moderators: phranque
And here comes the problem. i want to avoid duplicate content so if a user accesses page1.php i want a permanent redirect to page1. Nothing that i found works for me.
If i cannot make a generalized redirect for this i'm thinking to take each page individual and do something like :
RewriteRule ^page\.php$ http://www.example.ro/page [R=301,L]
the problem is i have over 70 links and growing :(.
Can you please help me with this ?
Thank you.
RewriteEngine On
#
# Internally rewrite extensionless URL to corresponding .php
# file unless the URL exists as a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(([^/]+/)*[^.]+)$ $1.php [L]
#
# Externally redirect (only) direct client requests for .php URLs to extensionless URLs
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://www.example.com/$1 [R=301,L]
Jim
If you do this, I suggest ordering the rules with the .php-extension to extensionless URL redirect first, the domain redirect second and the extensionless-to-php internal rewrite last. This will prevent multiple redirects in the case of wrong-domain/file.php, and prevent 'exposing' the internal .php filepath to the client as a URL in the case of an extensionless URL request to the wrong domain.
Jim
So your list above would be better ordered as 1-4-2-3 or 4-1-2-3. "4" and "1" are likely mutually-exclusive, so they can be in either order -- or even 'mixed together' if that makes more sense from a "self-documenting-code" standpoint.
Jim