Forum Moderators: phranque
Add .php to the first part of the uri segment.
[abc.com...] will redirect to
[abc.com...]
Is this possible? It appears simple but whatever I try is putting this server to infinite loop or it is adding .php to the last segment.
Any help is so much appreciated...
An internal rewrite might be more appropriate.
Since you did not post your code, I cannot comment on the cause of the loop other than to say that you must exclude the 'output' of the redirect or rewrite so that it does not match the 'input' pattern. If it does match, then a loop is the natural result. Usually, making the rule pattern more specific or using a RewriteCond to explicitly exclude the output path will easily solve this problem.
(A search here on WebmasterWorld for "rewrite loop" and/or "redirect loop" will turn up hundreds of previous threads on this subject.)
Jim
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ $1.php/$2 [L]
</IfModule>
Furthermore, there is nothing in the pattern to reject paths that already have had .php added in, so this rule will loop on itself (in .htaccess, mod_rewrite processing is re-started whenever any rule has matched).
This modified pattern will be better with respect to fixing those problems, but I can't be sure what other URLs your site might use, so no guarantees:
RewriteRule ^([^/.]+)/([^/]+/[^/]+)/?$ $1.php/$2 [L]
For every page or 'resource' on your site, there should be one and only one unique/canonical URL that can be used to reach it directly. All non-canonical variations of protocol (http vs. https), subdomain (e.g. 'www.'), domain, FQDN, port number, URL-path, and query string (if applicable) should be redirected to the canonical URL.
For example, many sites have a home page that can be reached at any of these URLs:
example.com/
example.com./
example.com:80/
example.com.:80/
www.example.com/
www.example.com./
www.example.com:80/
www.example.com.:80/
example.com/index.html
example.com./index.html
example.com:80/index.html
example.com.:80/index.html
www.example.com/index.html
www.example.com./index.html
www.example.com:80/index.html
www.example.com.:80/index.html
Whichever of those URLs is "correct" in the eyes of the Webmaster, it is competing with 15 identical copies of itself for links and ranking!
Jim