0

I am getting a "webpage has a redirect loop" error on my rewrite rules in Apache.

I want to have clean URLs for GET requests so if a user types www.flavor.com/vanilla that the server runs www.flavor.com/?s=vanilla but the url reads just www.flavor.com/vanilla so I added this:

RewriteRule ^([a-z]+)$ /?s=$1

This works fine, but I also want to have www.flavor.com/?s=vanilla to redirect to www.flavor.com/vanilla so I added this which is causing a loop.

RewriteCond %{QUERY_STRING} ^s=([a-z]+)$
#RewriteRule ^(.*)$ /%1? [L,R=301]

I tried adding [END] and [L] to the both, but no help. I've rewritten this 200 times and can't figure it out.

julienc
  • 19,087
  • 17
  • 82
  • 82

1 Answers1

0

As answered here and here this should help: RewriteCond %{ENV:REDIRECT_STATUS} 200.

Full file:

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^([a-z]+)$ /?s=$1
RewriteCond %{QUERY_STRING} ^s=([a-z]+)$
RewriteRule ^(.*)$ /%1? [L,R=301]
Community
  • 1
  • 1
Glapa
  • 790
  • 10
  • 20
  • I tried this, but am getting the following error message: Not Found The requested URL /example was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Apache Server at mysite.org Port 80 – Adam Wohlberg Jul 18 '14 at 00:01