How do I write multiple rewrite terms and conditions in a single .htaccess file to redirect URLs?

I have a sub-site called subsite.site.com (just an example). Firstly, I want to redirect subsite.site.com to www.subsite.site.com , and finally, I want to redirect www.subsite.site.com to www.subsite.site.com/directory/subdirectory/index.html

The following rewriting conditions and rules serve this purpose independently.

 RewriteEngine on RewriteCond %{HTTP_HOST} ^subsite.site\.com RewriteRule ^(.*)$ http://www.subsite.site.com/$1 [R=301,L] 

 RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.subsite\.site\.com$ RewriteRule ^/?$ "http\:\/\/www\.subsite\.site\.com\/directory\/subdirectory\/" [R=301,L 

How to combine the two above conditions and rules in a single .htaccess file?

thanks,

+4
source share
1 answer

How to combine the two above conditions and rules in a single .htaccess file?

Just put one by one in one file:

 RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.subsite\.site\.com$ [NC] RewriteRule ^/?$ /directory/subdirectory/ [R=301,L] RewriteCond %{HTTP_HOST} ^subsite.site\.com [NC] RewriteRule ^(.*)$ http://www.subsite.site.com/$1 [R=301,L] 
+6
source

Source: https://habr.com/ru/post/1490021/


All Articles