Simple .htaccess RewriteRule not working

Not sure why this is not working:

RewriteEngine On

RewriteCond %{HTTP_HOST} example.com$ [NC]
RewriteRule ^.+ http://example.com [L]

RewriteCond works as far as I can tell.

For me RewriteRulereads:

  • ^ Start match
  • .+ One or more characters

However, Firefox 44 tells me

Page not redirecting correctly

Firefox has detected that the server redirects the request to this address in a way that will never be completed.

If it RewriteRulestarted with ^.*, I would expect the server to be caught in an infinite loop.

But it ^.+should work, no?

+4
source share
1 answer

You get a redirect loop by adding a handler DirectoryIndexto REQUEST_URI.

, :

RewriteCond %{HTTP_HOST} www.localhost$ [NC]
RewriteCond %{REQUEST_URI} !^/index\. [NC]
RewriteRule ^.+ http://www.localhost [L,R]

RewriteCond %{REQUEST_URI} !^/index\. [NC] , /index.html /index.php DirectoryIndex.

+3

Source: https://habr.com/ru/post/1627985/


All Articles