我遇到了htaccess设置问题。我的目标是让通配符子目录指向相应的文件夹,但不更改URL。我在这里关于stackoverflow和其他地方的一些例子。我已经在DNS中使用了我的通配符,虚拟主机很适合去和mod包。剩下的就是指向匹配文件夹的htaccess而不更改浏览器中的URL。
此工作原理如下所示,我看到了domain.com/example/index.html文件(但是,在浏览器中,网址从example.domain.com更改为domain.com/example)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/%1/$1 [L,NC,QSA]
</IfModule>
当我换出P标志的L标志时,url不会改变。当我这样做并尝试example.domain.com时,url不会按预期更改,但它会告诉我如果我去了domain.com而不是/ example文件夹中的内容,我会看到什么。
以下是我的内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/%1/$1 [P,NC,QSA]
</IfModule>
我做错了什么?
答案 0 :(得分:0)
您正在尝试在替换中提供URL,这会导致重定向。尝试简单地按如下方式设置配置:
VirtualHost
ServerName example.com
ServerAlias *.example.com
DocumentRoot /path/to/your/doc/root
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$
RewriteCond %{REQUEST_URI} !^/%1 [NC]
# Please confirm whether you need the next line in your rules.
# I should think that it'd be required
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$
RewriteRule ^ /%1%{REQUEST_URI} [L,QSA]