[英].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.