Forum Moderators: phranque
On my site i rewrite urls like so
RewriteRule ^([A-Za-z0-9_-]+)\.html$ /index.php?section=$1&%{QUERY_STRING} [L]
index.php?var=myvar
so i want to say
RewriteRule ^index.php /index.html [R=301,NC,L]
Is there any way i can get round this? the only way i can think of at the moment is to rename my index.php page to site.php but this seems a bit drastic.
Any help massively appreciated.
Ally
[edited by: Scally_Ally at 5:35 pm (utc) on Feb. 19, 2009]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php[^\ ]*\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/index.ht[b]ml?[/b] [R=301,L]
Note that I recommend dumping the "index.html" if possible, and simply redirecting to "www.example.com/". Try this after testing the rule as written above.
This redirect rule should go before your general domain canonicalization redirect (if you have one), and all such external redirect rules should be placed before all of your internal rewrite rules.
Jim
[edit] Corrected code to fix problem reported below. [/edit]
[edited by: jdMorgan at 4:19 pm (utc) on Feb. 24, 2009]
this worked well in stopping the infinite loop, the only problem that i have now is that the querystring then gets attached to the index.html page. I have done alot of research but cannot find how to stop the querystring getting passed across.
The redirect at the moment goes
http://www.example.com/index.php?cat=sdasasas
goes to
http://www.example.com/index.html?cat=sdasasas
I just want it to go to
http://www.example.com/index.html
without the query string.
Many thanks again.
Ally
I have taken your advice g1smd - my rewrite now looks like
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php[^\ ]*\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/? [R=301,NC,L]
So it doesnt incorporate the index.html
Thanks again
Ally