4

I have one .htaccess file in the public_html folder of my server that lets me keep my primary 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]        

In that subfolder is another .htaccess with more rewrites to turn urls ending with things like /index.php?page=about into 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 rewrite for just the domain name (\^$) is broken. Everything works on my local MAMP server, but the first .htaccess file is not present there, so I'm thinking that the two are conflicting. Any web dev champs able to see what's going wrong?

mabarroso
  • 659
  • 2
  • 11
  • 23

3 Answers3

0

Try commenting out:

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

It looks like the regex ^(.*)$ will match anything including blank strings, which would conflict with RewriteRule ^$ index.php?page=home

Edit: Try using ([A-Za-z0-9]+) in place of the ^(.*)$ which should give you:

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

Stegrex
  • 4,004
  • 1
  • 17
  • 19
0

You can always set up a rewrite log to see what's going on http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog

0

I'm assuming you have a /mrmikeanderson/ folder where the 2nd htaccess file is. The reason why the RewriteRule ^$ index.php?page=home isn't being applied is because you are redirecting the / request to mrmikeanderson/index.php. So either change this rule:

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

to

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

or change this rule in the other htaccess file:

RewriteRule ^$ index.php?page=home

to

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

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

Jon Lin
  • 142,182
  • 29
  • 220
  • 220