0
votes

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

2

2 Answers

2
votes

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
0
votes

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/"