Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"OR" Flag in .htaccess mod_rewrite

Just found this .htaccess rewrite code

RewriteEngine on RewriteCond %{HTTP_HOST} ^my.domain.com$ [NC,OR] RewriteCond %{REQUEST_URI} !public/ RewriteRule (.*) /public/$1 [L] 

And I was wondering what was the purpose of the "OR" flag. Already checked the doc http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteflags but coulnd find any infos.

Any ideas?

like image 877
gabriel-kaam Avatar asked Sep 18 '12 20:09

gabriel-kaam


People also ask

What is RewriteRule * F?

RewriteRule "\.exe" "-" [F] This example uses the "-" syntax for the rewrite target, which means that the requested URI is not modified. There's no reason to rewrite to another URI, if you're going to forbid the request.

What does IfModule mod_rewrite C mean?

The <IfModule mod_rewrite. c>... </IfModule> block ensures that everything contained within that block is taken only into account if the mod_rewrite module is loaded. Otherwise you will either face a server error or all requests for URL rewriting will be ignored.

What is RewriteCond in htaccess?

htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.

What is QSA in htaccess?

QSA means that if there's a query string passed with the original URL, it will be appended to the rewrite ( olle? p=1 will be rewritten as index.


2 Answers

from http://httpd.apache.org/docs/current/mod/mod_rewrite.html

ornext|OR (or next condition) Use this to combine rule conditions with a local OR instead of the implicit AND. Typical example:

RewriteCond %{REMOTE_HOST}  ^host1  [OR] RewriteCond %{REMOTE_HOST}  ^host2  [OR] RewriteCond %{REMOTE_HOST}  ^host3 RewriteRule ...some special stuff for any of these hosts... 
like image 64
waraker Avatar answered Oct 05 '22 01:10

waraker


[OR] is used when you want to have, one OR another OR another condition, trigger the rewriterule. Otherwise the default behavior is 'AND' All of the RewriteConds have to be true in order to trigger the rule.

like image 34
Boz Avatar answered Oct 05 '22 00:10

Boz