user2217162
user2217162

Reputation: 905

RewriteCond for either .com or .org

Is there a way I can simplify this code so I dont have to check .com and .org separately?

RewriteCond %{HTTP_HOST}   ^(www\.)?mywebsite\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/mydirectory(/.*)?$ [NC]
RewriteRule ^(.*)$         /mydirectory/$1    [QSA,L]

RewriteCond %{HTTP_HOST}   ^(www\.)?mywebsite\.org$ [NC]
RewriteCond %{REQUEST_URI} !^/mydirectory(/.*)?$ [NC]
RewriteRule ^(.*)$         /mydirectory/$1    [QSA,L]

Upvotes: 0

Views: 141

Answers (1)

anubhava
anubhava

Reputation: 785541

Yes you can take regex help for that. Try this:

RewriteCond %{HTTP_HOST} ^(www\.)?mywebsite\.(com|org)$ [NC]
RewriteCond %{REQUEST_URI} !^/mydirectory(/.*)?$ [NC]
RewriteRule ^(.*)$ /mydirectory/$1 [L]

Take note of (org|com) which makes that patter match both .org and .com

Upvotes: 2

Related Questions