[英].htaccess redirect to another folder but keep the original domain
第一的,
我的'example.com'
域鏈接到'/home/defaultfolder/'
文件夾。
我想重定向
example.com , www.example.com
到
/home/somefolder/example/
,而不是/home/defaultfolder/
文件夾
通過使用 .htaccess。 (兩者都在 DocumentRoot 目錄中)
此外,子域如
a.example.com
到
/somefolder/example/a/
但保留“example.com”域。
我在網上嘗試了一些示例,但沒有任何方法可以做到。
我如何編寫 .htaccess 來做到這一點? 謝謝你。
當然,我無法更改服務器設置(如別名虛擬主機..),這就是我嘗試通過修改文件來做到這一點的原因。
我試過了
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule /somefolder/example/$1 [R=301,NC,L]
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule !^/somefolder/example/ /somefolder/example/1%{REQUEST_URI} [L]
RewriteCond %{HTTP_HOST} ^/?(?:www\.)?example.com
RewriteRule ^(.*)$ /somefolder/example/$1 [R=permanent,L]
和其他一些..
在/home/.htaccess
(站點根目錄)中這樣設置:
RewriteEngine On
# handle example.com
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example)\.com$ [NC]
RewriteRule .* somefolder/%1/$0 [L]
# handle any sub.example.com
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^([^.]+)\.(example)\.com$ [NC]
RewriteRule .* somefolder/%2/%1/$0 [L]
我認為您應該修改服務器設置,將域根文件夾設置為您想要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.