dudongpuge
dudongpuge

Reputation: 11

Combine .htaccess files to a single working one

I have .htaccess files on every subfolder in demo.mydomain.net to redirect to mydomain.net without redirecting image/js files.

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/load
RewriteRule ^/?$ "http\:\/\/mydomain\.net" [R=301,L]

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/load/images
RewriteRule ^/?$ "http\:\/\/mydomain\.net" [R=301,L]

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/load/scripts
RewriteRule ^/?$ "http\:\/\/mydomain\.net" [R=301,L]

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/load/styles
RewriteRule ^/?$ "http\:\/\/mydomain\.net" [R=301,L]

Is there any way I can combine these to a single working file and save it to where my index file is?

Upvotes: 1

Views: 41

Answers (1)

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51711

You would need the following combined rule within the .htaccess in your directory mapped to demo.mydomain.net

RewriteEngine on

RewriteCond %{REQUEST_URI} ^/load(/(images|scripts|styles))? [NC]
RewriteRule ^ http://mydomain.net [R=301,L]

The above %{REQUEST_URI} regex intercepts all four URL paths.

Upvotes: 2

Related Questions