apache - .htaccess Too Many Redirects (Combining 404 With Remove www) -


using .htaccess, i'm able remove www site url or i'm able handle 404 redirects nonexistent page on site. however, if try have both, error saying "too many redirects" , site won't load anymore. how can fix can both remove www , have 404 redirects without problems?

edit: original post not duplicate.

.htaccess code:

rewriteengine on rewritecond %{http_host} ^www\.(.+)$ [nc] rewriterule ^(.*)$ http://%1/$1 [r=301,l] rewritecond %{http_host} ^([a-z.]+)?example\.com$ [nc] rewritecond %{http_host} !^www\. [nc] rewriterule .? http://www.%1example.com%{request_uri} [r=301,l] 

give following set of rules try:

rewriteengine on  rewritecond %{http_host} ^www\.(.+)$ [nc] rewriterule . http://%1%{request_uri} [r=301,l]  rewritecond %{http_host} ^((?!www\.)[a-z.]+)example\.com$ [nc] rewriterule . http://www.%1example.com%{request_uri} [r=301,l] 

the redirect loop happens because you're redirecting urls http://www.%1example domain irrespective of whether %1 group exists or not.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -