1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

My .htaccess file used to work but now it's causing trouble. Please help.

Discussion in 'Apache' started by marcusa007, Oct 26, 2008.

  1. #1
    I have a directory that pulls data form a database and works on php.
    It is a tattoo directory. Everything worked fine when I bought the system.
    But a while ago the site started messing up and I cant figure out why. I have re-installed everything but no luck. I think it has something to do with the .htaccess file the rewrites to make things work.

    The front page used to have the states and news. Now when I enter www.besttattoodirectory.com it rewrites it to http://www.besttattoodirectory.com/state.php?s=index and the page shows the right page but no content. When I click on home from their it goes to the right page form their with all the content (http://www.besttattoodirectory.com/index.php)

    Hier is the .htaccess file:

    Options +FollowSymLinks
    RewriteEngine On

    RewriteRule ^tattoo/(.+)/(.+)/ s.php?s=$1&q=$2
    RewriteRule ^tattoo/(.+)/(.+)/(.+)/ bp.php?s=$1&telephone=$2&geo=$3
    RewriteCond %{HTTP_HOST} ^besttattoodirectory\.com [NC]
    RewriteRule ^(.*)$ http://www.besttattoodirectory.com/$1 [L,R=301]

    RewriteRule (.*).htm$ http://besttattoodirectory.com/state.php?s=$1


    The same thing happens when I get to the state level it used to show the news but now nothing. I have deleted the rewrite rules at this point the index loads correctly but the rest does not.

    Any help would be greatly appreciated.
     
    marcusa007, Oct 26, 2008 IP
  2. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think I have found the problem.

    It happens because Apache uses an internal rewrite to request an index page when the URL maps to a directory.

    Somewhere in your httpd.conf you will have a line that looks like this:
        DirectoryIndex index.htm index.php
    Code (markup):
    So if a user requests / (Which is what they are requesting when the URL is http://www.besttattoodirectory.com/) then Apache translates this into http://www.besttattoodirectory.com/index.htm to check if it exists.
    Then your last rewrite rule kicks in and redirects me to http://besttattoodirectory.com/state.php?s=$1. The reason it does a redirect instead of an internal rewrite is because you have specified a fully qualified URL instead of a relative one. If you changed the rewrite from this:
    RewriteRule (.*).htm$ http://besttattoodirectory.com/state.php?s=$1
    Code (markup):
    to this:
    RewriteRule (.*).htm$ /state.php?s=$1
    Code (markup):
    then it would all work invisibly. (although not as efficiently as it could.)

    As it is, the next thing that happens is that your www rewrite kicks in and redirects me to the same domain with www. in front of it.

    If you add this:
    RewriteCond %{REQUEST_URI} !index.htm
    Code (markup):
    in front of the last rule it will avoid matching the last rule on index pages. Alternatively, you could change your DirectoryIndex directive to not include index.htm.

    I also noticed that your first rule will match anything that would match your second rule and hence nothing will ever match the second rule. You might want to add a trailing $ after the final / in the first rule.
     
    Ladadadada, Oct 26, 2008 IP
    marcusa007 likes this.
  3. marcusa007

    marcusa007 Active Member

    Messages:
    312
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #3
    I just added the recommendations. And all works fine again. Thanks
     
    marcusa007, Oct 26, 2008 IP