Can .htaccess files be conflicting?

I have one .htaccess file in the public_html folder of my server, which allows me to save my main domain in a subfolder:

RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?mrmikeanderson.com$ RewriteCond %{REQUEST_URI} !^/mrmikeanderson/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /mrmikeanderson/$1 RewriteCond %{HTTP_HOST} ^(www.)?mrmikeanderson.com$ RewriteRule ^(/)?$ mrmikeanderson/index.php [L] 

There is another .htaccess in this subfolder with a lot of rewriting to include URLs ending in things like /index.php?page=about in just / about:

 RewriteEngine On RewriteRule ^$ index.php?page=home RewriteRule portfolio index.php?page=portfolio RewriteRule resume index.php?page=resume RewriteRule about index.php?page=about RewriteRule contact index.php?page=contact 

The last four pages work, but my correspondence only for the domain name (\ ^ $) is broken. Everything works on my local MAMP server, but the first .htaccess file is missing there, so I think the two are conflicting. Can any web developer see what is going wrong?

+4
source share
3 answers

I assume that you have the /mrmikeanderson/ folder where the second htaccess file is located. The reason RewriteRule ^$ index.php?page=home is not applied is because you are redirecting the / request to mrmikeanderson/index.php . Therefore, either modify this rule:

 RewriteRule ^(/)?$ mrmikeanderson/index.php [L] 

to

 RewriteRule ^(/)?$ mrmikeanderson/index.php?page=home [L] 

or change this rule in another htaccess file:

 RewriteRule ^$ index.php?page=home 

to

 RewriteRule ^(index.php)$ index.php?page=home 

Or you can modify your index.php file to assume that the page variable is home by default.

0
source

Try to comment:

RewriteRule ^(.*)$ /mrmikeanderson/$1

It looks like the regex ^(.*)$ Will match everything, including blank lines that conflict with RewriteRule ^$ index.php?page=home

Edit: Try using ([A-Za-z0-9]+) instead of ^(.*)$ , Which should give you:

RewriteRule ^([A-Za-z0-9]+)$ /mrmikeanderson/$1

0
source

You can always set up a rewrite log to find out what is going on at http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog

0
source

All Articles