Forum Moderators: phranque
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^folder/page\.htm$ /folder/page.php [L]
RewriteRule ^id(.*)\.htm$ /detail.php?id=$1 [L]
This works for me but can I redirect those that actually link to or try to type in 'page.php' to 'page.htm'? (my efforts created a loop). In other words, how do I properly hide 'page.php' and 'detail.php?' to users and search engines?
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^folder/page\.htm$ /folder/page.php [L]
RewriteRule ^id([^.]+)\.htm$ /detail.php?id=$1 [L]
So, to avoid the loop you've experienced, it is necessary to look at the original client request, so that your rules aren't fooled into rewriting a previously-rewritten URL.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /page\.php\ HTTP/
RewriteRule ^page\.php$ http://www.example.com/page.html [R=301,L]
GET /page.php HTTP/1.1
Apache vs. Windows reminds me of what an old skateboard friend said the first time we went snowboarding: "This is everything I wanted to do on a skateboard but couldn't".
Thanks again Jim.
You will find that writing mod_rewrite code is much, much easier than reading it. If you have a clearly-defined requirement, it's easy to come up with the code. But if you are looking at code, and trying to figure out what the requirement was, it's pretty tough.
The hard part about answering questions in this forum is to figure out:
1) What the poster wants to do
2) How the poster's files relate to his URLs, and how those files are organized in directories
3) How the poster's server is configured (different hosting companies do it differently)
The actual coding part is comparitively easy...
Jim