How do you combine these 2.htaccess RewriteRules into one?

Okay, I have another question and I'm starting with this.

I have this RewriteRule, it redirects the request correctly, but prevents me from using other directories:

RewriteRule ^([0-9A-Za-z]+)/?$ /query.php?id=$1 [L]

      

and now this RewriteRule will skip all these directories, but now you need to comment out the above rule for that.

RewriteRule ^(css|js|admin|pages|includes|images)(/|$) - [L]

      

Can the two be combined? If so, how?

+2


source to share


2 answers


RewriteRule

are checked in the order they appear in the file, so if you put a rule first css|js|admin|pages|includes|images

, it will match first and stop the rewrite process before another rule is reached. Just remember to leave the flag [L]

at the end of this rule.



+4


source


There's also this neat trick:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+) query.php?id=$1 [L]

      



That is, if the file path is not an existing file or directory, submit a request to the PHP script (so you can load some module dynamically or show a useful 404 page).

0


source







All Articles