views:

199

answers:

2

Hey guys,

My developer has provided me some Apache rewrite rules that are required for our application to work. When I added them to Apache my www.domain.com/blog and www.domain.com/phpmyadmin pages no longer worked. I tried to add the first RewriteCond rule for my blog and also the final phpmyadmin rule but neither one is working as expected. Essentially I want any requests to /blog or /phpmyadmin to NOT rewrite and go to my document root directory and run those applications outside of rewrites. Can you help me figure out a solution? Thanks

RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule ^/(.*_css.*\.css.*) /$1 [QSA,L]
RewriteRule ^/(.*_js.*\.js.*) /$1 [QSA,L]
RewriteRule ^/(.*_swf.*\.swf.*) /$1 [QSA,L]
RewriteRule ^/(.*_img.*\.[jpg|JPG|jpeg|JPEG|gif|GIF|bmp|BMP|png|PNG].*) /$1 [QSA,L]
RewriteRule ^/(.*)$ /index.php?url=$1 [QSA,L]
RewriteRule ^/phpmyadmin(.*)$ /phpmyadmin$1 [QSA,L]
</VirtualHost>

They are located at www.domain.com/blog and www.domain.com/phpmyadmin.

Apache 2.2.13

Thanks!

A: 

Err... not sure what you are trying to do. Are you trying to "Exclude" static files as images/stylesheets/flash movies/javascript files and the link to PHPMyAdmin? Maybe something like this could do the job for you 'quick 'n dirrrrty'

# Enable the RewriteEngine
RewriteEngine   On
RewriteBase  /

# Check if the file, directory or symlink does not already exists.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-F
RewriteCond %{REQUEST_FILENAME} !favicon\.ico
RewriteCond %{REQUEST_FILENAME} !robots\.txt

# Rewrite all other requests to the index.php
RewriteRule ^(.+)$  /index.php?url=$1  [QSA,L]
CharlesLeaf
Thanks for the feedback Charles, after putting these rules in place my Apache restart failed with this message:Syntax error on line 46 of /usr/local/apache2/conf/extra/httpd-vhosts.conf:RewriteBase: only valid in per-directory config filesI then removed the RewriteBase line and Apache started but my application was no longer working as expected.
roacha
He assumed that the line would be in a `.htaccess` file. You could try removeing the `RewriteBase` line. What is it you're trying to do?
Dave
Thanks Dave, I did remove the RewriteBase line and Apache started but my app was no longer working properly. All I am trying to do is add a rule that will not redirect my blog or phpmyadmin url. www.domain.com/blog and www.domain.com/phpmyadmin. I have both of these directories right off my document root.
roacha
A: 

If you want to avoid rewriting URLs that begin with /blog/ or /phpmyadmin/ then you may be able to get away with the first rule being:

RewriteRule ^/(?:blog|phpmyadmin)/ - [L]

(replacing your RewriteCond and then removing the old phpmyadmin rule).

A quick explanation: this matches any URLs that begin with /blog/ or /phpmyadmin/ and doesn't rewrite them (- for the replacement), and then stops any further rewriting ([L]).


Previous answer:

Your rewrite rules are conflicting, for a start. Also, at the moment, the RewriteCond only applies to the first rule. Also, the final rule is ignored because of the rule before it matching everything. You may want something like this:

RewriteRule ^/blog/(.*)$ /index.php?url=$1 [QSA,L]

as I assume you're just trying to rewrite all URLs from /blog/foo/bar to /index.php?url=foo%2fbar? If not, please explain what you're trying to accomplish and I'll edit my answer.

Dave
Thanks Dave, The first and last Rewrite rules are the ones I am working on changing, the others are used by our application. I have a blog and phpmyadmin dir right off document root. I do not want these being rewritten anywhere. When someone hits www.domain.com/blog or phpmyadmin I want those apps to work normally and not get rewritten. Currently they fall under one of the rewrite rules and do not work. Thanks
roacha
Dave I updated my initial question with more details, I hope that explains what I am trying to accomplish. Thanks!
roacha
For starters, then, you'll need to move the phpMyAdmin rule above the others, because like Dave said, the one right above it matches everything so the system will never even look at your phpMyAdmin rule as it's currently written.
Jason Rhodes
Thanks Dave! That worked perfectly! Appreciate it
roacha
Excellent! Just glad I can help :-)
Dave