Reputation: 3376
I have my .htaccess file setup like the following. It's a simple concept where all requests get forwarded to the cgi-bin/controller.rb except for those requests for anything in /images, /css, /javascripts, or /cgi-bin
I also want the root to just be redirected to /index/show but that's the part which is erroring. It just keeps infinitely redirecting to /index/showindex/showindex/show...
Can anyone explain why my redirectmatch doesn't work?
RedirectMatch permanent ^/$ /index/show
ErrorDocument 404 /404
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/images/ [NC]
RewriteCond %{REQUEST_URI} !^/css/ [NC]
RewriteCond %{REQUEST_URI} !^/javascripts/ [NC]
RewriteCond %{REQUEST_URI} !^/cgi-bin/ [NC]
RewriteRule (.*) /cgi-bin/controller.rb?%{QUERY_STRING}&page=$1 [L]
Upvotes: 1
Views: 3642
Reputation: 16825
Avoid using RedirectMatch and RewriteRule at the same time. Those are different modules and are applied at different times in the request-flow. You can achieve the same using only RewriteRule's:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index/show [NC]
RewriteRule ^$ /index/show [L]
RewriteCond %{REQUEST_URI} !^/index/show [NC]
RewriteCond %{REQUEST_URI} !^/images/ [NC]
RewriteCond %{REQUEST_URI} !^/css/ [NC]
RewriteCond %{REQUEST_URI} !^/javascripts/ [NC]
RewriteCond %{REQUEST_URI} !^/cgi-bin/ [NC]
RewriteRule (.*) /cgi-bin/controller.rb?page=$1 [L,QSA]
Optionally use RewriteRule ^$ /index/show [L,R=301]
if you really want the redirect, instead of leaving the address bar nice and clean.
Also remember to clear the browsers cache, as the Permanent redirect are cached very aggressively.
Upvotes: 3