Prevent .htaccess 301 redirects on subdomain

Prevent .htaccess 301 redirects on subdomain - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, redirects, , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I have 301 redirects which direct /index.html to /site folder and when I created a subdomain it also redirects the link to /site which causes 404 Not Found.



For example: members.mysite.com redirects to members.mysite/site which causes 404 error
can I add execption for specific forlder or something without changing the redirect.



.htaccess content:



AddType text/x-server-parsed-html .htm .html
RedirectMatch 301 ^/index.html(.*)$ /site$1

Solution :

.htaccess rules apply to every subfolder that are within the folder with that .htaccess file. To stop your root .htaccess file affecting your subdomains, you should create your subdomain folders outside of the public_html folder on your server.



Also the problem with your redirect is that you are using redirect match, try a redirect that specifies the absolute path, such as:



RewriteCond %HTTP_HOST  ^www.mysite.com$ [NC]
RewriteCond %QUERY_STRING ^$
RewriteRule ^index.html$ /site? [R=301,NE,NC,L]

Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect