How to remove a subdirectory from the url when forwarding to sudirectory?

三世轮回 提交于 2019-12-02 11:25:29

问题


On a shared server I am forced to manage document roots of domains from cpanel which is buggy and consumes lots of time. So I redirected all domains to one directory lets say root. An example:

sd1.domain.com  ---> public_html/web/
sd2.domain.com  ---> public_html/web/
sd1.domain2.com ---> public_html/web/
sd2.domain2.com ---> public_html/web/

When user browses these websites, I forward this websites using htaccess rules such as

RewriteCond %{HTTP_HOST}   ^sd1.(domain1|domain2).com [NC]
RewriteCond %{REQUEST_URI} !^/sd1/.*
RewriteRule   ^(.*)  sd1/$1  [L]

Now this does forward the request to different folder but afterwards all the url have sd1 attached on the last part

Here is an illustration

sd1.domain.com            ---> sd1.domain.com                 #Works correctly
sd1.domain.com/page1.html ---> sd1.domain.com/sd1/page1.html  # See the word sd1 on the middle

How to remove the folder portion from the url??


回答1:


if I understand your question correctly, you should be able to do it by using the flag PT (Passthru), which causes the rewrite target to be passed back to the URL mapping engine:

RewriteCond %{HTTP_HOST}   ^sd1.(domain1|domain2).com [NC]
RewriteCond %{REQUEST_URI} !^/sd1/.*
RewriteRule   ^(.*)  sd1/$1  [PT,L]

Hope it helps.



来源:https://stackoverflow.com/questions/17937873/how-to-remove-a-subdirectory-from-the-url-when-forwarding-to-sudirectory

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