Apache ReWrite rule stopping portions of our app

Our application uses rewrite rules in our PHP application and our developer added these rewrite rule to our Apache VHosts file:

I have updated our Rewrite rules based on suggestion below.

Currently my VHosts file configuration looks like this:

RewriteCond %blog !-d RewriteRule ^/([a-zA-Z0-9-,]+)/?$ /index.php?a=$1

RewriteCond %blog !-d RewriteRule ^/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/?$ /index.php?a=$1&b=$2

RewriteCond %blog !-d RewriteRule ^/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/?$ /index.php?a=$1&b=$2&c=$3

RewriteCond %blog !-d RewriteRule ^/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/?$ /index.php?a=$1&b=$2&c=$3&d=$4&e=$5

I am able to currently access all of our other application tabs successfully such as /goods,etc. But I still cannot access www.test.com/blog

It is still redirecting me to our application's main index.php page. From the rewrite logs:

[13/Oct/2009:17:08:41 --0400] [www.test.com/sid#8d03d8][rid#b902d8/initial] (1) pass through /blog/wp-login.php [13/Oct/2009:17:08:41 --0400] [www.test.com/sid#8d03d8][rid#b942f8/initial] (1) go-ahead with / /public_html/index.php [OK]

Thanks

13.10.2009 15:27:50
2 ОТВЕТА

You are trying a lot of stuff in your rewrite rules. I advice you not to.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /index.php?url=$0 [PT,L]

I advise you to rewrite the complete string to $_GET['url'] variable. You could explode this variable in you code. This way you have to edit your vhost only once.

The RewriteCond still counts in bothways (in the above and below example).

These rewrite conditions will check if a file or directory exists. If not it will apply the rewrite rule

if the conditions will not work try to place the condition above every RewriteRule like this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([a-zA-Z0-9-,]+)/?$ /index.php?a=$1 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/?$ /index.php?a=$1&b=$2 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/?$ /index.php?a=$1&b=$2&c=$3 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/([a-zA-Z0-9-,]+)/?$ /index.php?a=$1&b=$2&c=$3&d=$4
2
13.10.2009 19:03:38
Thanks for the feedback Robert. After trying your recommendations I realized my original question description was not accurate. If you have time could you please review my updated description. Thanks again!
Steve 13.10.2009 16:41:53
Is my solution still valid, Steve?
Robert Cabri 13.10.2009 18:58:22
Robert, I tried the updated commands above with the ReWriteCond specified above each rule but I am still getting the same behavior. Please see my updated description. Thanks again for taking the time to help.
Steve 13.10.2009 21:25:00
Steve, RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d may not be changed. Do not change {REQUEST_FILENAME} into blog. Let these rewriteconditions unchanged
Robert Cabri 13.10.2009 23:17:06
Thanks Robert. I made the changes you suggested and I am able to access my /blog/index.php and /blog/wp-login.php. But I cannot access any directories under blog. For example blog/wp-admin/ fails which is where wordpress takes me after logging in the first time. One other issue with these changes is our application tabs do not have directories for each tab topic under our DocRoot. So certain application tabs no longer work with this new change. Thanks for the feedback.
Steve 14.10.2009 14:00:00

Try using the conditions

RewriteCond %{REQUEST_URI} !^/blog$ [OR]
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule ^/([a-zA-Z0-9-_,]+)/?$ /index.php?a=$1

It's a matter of playing with conditions and regexes. This should prevent triggering the rewriterule when the URI starts with "/blog/"

0
14.11.2009 17:28:25
Thanks for your input Michal. I have modified the Rewrite Rules to match your example above. But now I am seeing strange behavior. I can go to my site, www.dudeimgettingmarried.com and click on the bubble icon to get to www.dudeimgettingmarried.com/blog and it loads perfectly. But if I type in that url directly into my browser it gets redirected into a failed page. Any ideas why? I am also able to access my Wordpress admin page via a bookmark but when I try the true URL it fails again with redirect issue: dudeimgettingmarried.com/blog/wp-admin/wp-login. Any ideas? Thanks
Steve 11.11.2009 16:53:08
Yeah, I've changed the post. The problem was with the trailing slash. Now it should work even if you type example.com/blog and example.com/blog/
michal kralik 14.11.2009 17:29:07