jdMorgan

msg:3961644 | 11:12 am on Jul 29, 2009 (gmt 0) |
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]
Note that it should not be necessary to check for "file exists" on an extensionless URL request, because all files on your server should have an extension. The only check needed is for "directory exists", since an extensionless URL may exist as a directory if a slash is added (automatically) to that URL. Jim
|
junglesnail

msg:3961648 | 11:19 am on Jul 29, 2009 (gmt 0) |
Jim, It works. A lot of thanks for helping out. Could there be another duplicate content if i also fix the www and non-www to be the same?
|
junglesnail

msg:3961649 | 11:20 am on Jul 29, 2009 (gmt 0) |
*sorry i ment *duplicate content issue
|
jdMorgan

msg:3961679 | 12:05 pm on Jul 29, 2009 (gmt 0) |
Redirecting non-www to www (or the reverse) will *prevent* a duplicate-content issue. 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
|
junglesnail

msg:3961691 | 12:13 pm on Jul 29, 2009 (gmt 0) |
I will Thanks a lot Jim
|
junglesnail

msg:3962362 | 9:00 am on Jul 30, 2009 (gmt 0) |
I forgot to tell you. I'm actually moving a site from .html to .php I also have to redirect the old html files to the new extensionless. Where should i place them ? Can the rules order be : 1).php-extension to extensionless URL redirect 2)the domain redirect 3)internal rewrite 4) redirect from old html to the new extensionless page by page. Am i getting this right ?
|
jdMorgan

msg:3962538 | 2:58 pm on Jul 30, 2009 (gmt 0) |
No, your redirects must precede your internal rewrite. Further, page-by-page redirects are most-specific, and so should precede the domain redirect. 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
|
g1smd

msg:3963832 | 7:24 pm on Aug 1, 2009 (gmt 0) |
If "going extensionless" for the .html URLs is merely removing the .html part from the URL, you could simply add a local OR to your .php URL redirect: \.php becomes \.(php¦html?) However, your words "page by page" maybe hint that the old and new names are not similar.
|
|