How to write multiple rewrite conditions and rules in one .htaccess file for redirecting urls?

早过忘川 提交于 2019-12-05 02:27:53

问题


i have sub-site named subsite.site.com (just and example). firstly i want to redirect subsite.site.com to www.subsite.site.comand and finally i want to redirect www.subsite.site.com to www.subsite.site.com/directory/subdirectory/index.html

the following rewrite conditions & 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 shall i combine the above two conditions & rules in a single .htaccess file?

thanks,


回答1:


how shall i combine the above two conditions & rules in a single .htaccess file?

Just put one after the other in the same 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]


来源:https://stackoverflow.com/questions/17501235/how-to-write-multiple-rewrite-conditions-and-rules-in-one-htaccess-file-for-red

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!