Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I can't figure out what's going on here... I am using WAMP = Windows Apache MySQL PHP packaged. I have 2 sites running locally, literally copies of each other from the start with modification. However on one /forum/ will go to load my /forum/index.php and on the other it will just go to the main index.php as directed from the other redirect rules. This .htaccess rewrites all my URLs to point to my site's configuration.

Something's going on here, other than the .htaccess I'm not sure where to look.

    RewriteEngine on

    RewriteCond    %{REQUEST_URI}  ^[^.]+$
    RewriteRule    ^(.+[^/])$           /$1/  [R=301,L]

    #Don't break valid URL's!
    RewriteRule ^forum/(.+)$ forum/$1 [L]
    RewriteRule ^image/(.+)$ image/$1 [L]
    RewriteRule ^feed/(.+)$ feed/$1 [L]
    RewriteRule ^sitemap/(.+)$ sitemap/$1 [L]
    RewriteRule ^cron/(.+)$ cron/$1 [L]
    RewriteRule ^lib/(.+)$ lib/$1 [L] [NS]
    RewriteRule ^index.php$ index.php?%{QUERY_STRING} [L] [NS]



#But fix the ones that need fixing
RewriteRule ^([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/?$ /index.php?cmd=$1&sec=$2&subsec=$3&tiersec=$4&quadsec=$5&act=$6&%{QUERY_STRING} [L,NS]
RewriteRule ^([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/?$ /index.php?cmd=$1&sec=$2&subsec=$3&tiersec=$4&act=$5&%{QUERY_STRING} [L,NS]
RewriteRule ^([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/?$ /index.php?cmd=$1&sec=$2&subsec=$3&act=$4&%{QUERY_STRING} [L,NS]
RewriteRule ^([^/]+?)/([^/]+?)/([^/]+?)/?$ /index.php?cmd=$1&sec=$2&act=$3&%{QUERY_STRING} [L,NS]
RewriteRule ^([^/]+?)/([^/]+?)/?$ /index.php?cmd=$1&act=$2&%{QUERY_STRING} [L,NS]
RewriteRule ^([^/]+?)/?$ /index.php?cmd=$1&%{QUERY_STRING} [L,NS]
share|improve this question

2 Answers 2

up vote 1 down vote accepted

It could be possible that your problem is not necesarly on the .htaccess, but in the virtualhost definition. Check that you have properly configured the AllowOverride and option directives for htaccess' directory (mod_rewrite requires AllowOverride FileInfo, and Options FollowSymLinks):

<Directory /your/path/to/forum>
  AllowOverride FileInfo
  Options FollowSymLinks
 </Directory>
share|improve this answer
    
I have 2 sites running off of the site with no difference at all to the virtual host configuration and this still doesn't work.... it's frustrating –  Webnet Oct 4 '10 at 2:28
    
Let us know the virtualhost configuration (or at least the configuration for the directory in which you have this .htaccess). –  Torian Oct 4 '10 at 13:41

Agreed with Torian's response, but I can also clean up your rewrites a bit:

#But fix the ones that need fixing
RewriteRule ^([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/?$ /index.php?cmd=$1&sec=$2&subsec=$3&tiersec=$4&quadsec=$5&act=$6 [L,NS,QSA]
RewriteRule ^([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/?$ /index.php?cmd=$1&sec=$2&subsec=$3&tiersec=$4&act=$5 [L,NS,QSA]
RewriteRule ^([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/?$ /index.php?cmd=$1&sec=$2&subsec=$3&act=$4 [L,NS,QSA]
RewriteRule ^([^/]+?)/([^/]+?)/([^/]+?)/?$ /index.php?cmd=$1&sec=$2&act=$3 [L,NS,QSA]
RewriteRule ^([^/]+?)/([^/]+?)/?$ /index.php?cmd=$1&act=$2 [L,NS,QSA]
RewriteRule ^([^/]+?)/?$ /index.php?cmd=$1 [L,NS,QSA]

It's not clear what the purpose of the "?"'s that aren't after the final "/" are, so I left them. But I suspect that:

^([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)/?$ 

could be replaced with:

^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$

without changing anything about the regex's behavior.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.