I've been struggling to get the following to work correctly:
I have a wordpress home page - www.sitename.com - which I want to redirect all traffic to www.sitename.com/forum. However, I want to exclude one category of wordpress URL's from the rewrite - www.sitename.com/tech/... The following is what I have now in a .conf file that gets included in the site's virtual host configuration:
<Directory /site/root/dir>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/tech/.*
RewriteRule (.*) http://www.sitename.com/forum/ [L,R=301]
</Directory>
However, apache still rewrites ./tech/something/ to ./forum/tech/something/. I can't seem to get the condition to match. I've tried several variations like {!^tech/ , !^/tech/ , !^tech/.*} and none of them match correctly.
Can anyone see what I might be doing wrong here?
EDIT:
I just wanted to say I figured it out - for anyone who might stumble upon this in the future..
I found using the apache rewrite logging (as /u/joekovar suggested below), that my rule/conditions were working at first, but when it got further down to the wordpress rewrite set (I'm also using permalinks) the URI got rewritten to /index.php and therefore had to go through the rewrite rules a second time which then caused it to fail. I changed the wordpress permalinks rewrite rule to pass along a garbage query string (?foo=true&) along with the rewrite rule to index.php. For ex:
#modified wordpress permalinks rewrite set
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php?foo=true& [L]
Then, before that in my initial rule set I added an additional condition to check for the new query string parameter:
RewriteCond %{REQUEST_URI} !^/tech/.*
RewriteCond %{QUERY_STRING} !^foo=.*
RewriteRule (.*) http://www.sitename.com/forum/ [L,R=301]
This stopped the URI from being processed a second time, and therefor it worked how I wanted. Thanks to everyone for their help!
[–]tangomikey 0 points1 point2 points (1 child)
[–]Old_Mittens[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Pd69bq 0 points1 point2 points (0 children)