.htaccess - redirection via ht access file is not working properly -


here scenario:

there website named "example.com" , folder named "mobile" accessing website via mobile or tab

if user types "example.com" in browser should redirected https://www.example.com working per below code in .htaccess:

rewritecond %{http_host} ^example\.com$ rewriterule ^/?$ "https\:\/\/www\.example\.com" [r=301,l] 

alternatively, if user accessing url https://www.example.com mobile should redirected https://mobile.example.com

now, whenever accessing url https://www.example.com mobile redirects browser https://mobile.example.com again per code in .htaccess considers specific part of url "example.com" , redirects browser https://www.example.com , way ends in infinite loop generating error:

"fetching page exceeded maximum of 10 redirects."

i tried putting in .htaccess file not redirect https://www.example.com in case there "mobile" word prefix not working

  rewritecond %{http_host} ^example\.com$   rewriterule ^mobile/ - [l]   rewriterule ^/?$ "https\:\/\/www\.example\.com" [r=301,l] 

please advise.

this how .htaccess file constructed

rewriteengine on  rewriterule ^mobile - [l]  rewritecond %{http_host} ^example\.com$ rewriterule ^/?$ "https\:\/\/www\.example\.com" [r=301,l]  rewriteengine on rewritecond %{https} !=on rewriterule ^/?(.*) https://%{www.example.com}/$1 [r,l]  ##disable viewing directories## options -indexes ##disable viewing directories##  ##disable viewing directories files## rewriteengine on  rewritecond %{http_referer} !^https://(www\.)?example.com [nc] rewritecond %{http_referer} !^https://(www\.)?example.com/.*$ [nc] rewriterule .*\.(png|gif)$ - [f,nc] ##disable viewing directories files##  ##disable viewing admin directory files## rewriteengine on  rewritecond %{http_referer} !^https://(www\.)?example.com [nc] rewritecond %{http_referer} !^https://(www\.)?example.com/.*$ [nc] rewriterule ^admin/.+\.php$ - [f,l] ##disable viewing admin directory files## 

redirection code header.php

<script type="text/javascript"> if (screen.width <= 699) { document.location = "https://mobile.example.com"; } </script> 

you not using rewritecond correctly. if want skip url rewriting when uri /mobile/ , redirect example.com https://www.example.com can use following

#skip url rewriting if requested uri /mobile rewriterule ^mobile - [l] #redirect example.com/ http://www.example.com/ rewritecond %{http_host} ^example.com$ rewriterule ^/?$ https://www.example.com/ [l,r] 

/ not special char in mod-rewrite , dont need escape it.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -