【发布时间】:2014-07-02 00:39:08
【问题描述】:
我想创建子域,以便我可以使用地址 test.mydomain.com。
在网上搜索和大量试验后,我在我的 .htacces 文件中得到了这个:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com(:80)?$
RewriteCond %{DOCUMENT_ROOT}/subdomains/%1/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/subdomains/%1/$1 -d
RewriteRule (.*) /subdomains/%1/$1 [L]
</IfModule>
如果我在浏览器中写 http://test.mydomain.com/folder/ 一切都很好。
但如果我写 http://test.mydomain.com/folder (没有结束斜杠),它会被重定向到 http://test.mydomain.dk/subdomains/test/folder /,这是浏览器中显示的地址(我不要)
我的问题是:
如何防止重定向?
我只想在浏览器中看到 http://test.mydomain.com/folder。不管结尾的斜线如何。
我的网页文件是这样的:
.htaccess
index.php (page for mydomain.com)
\subdomains
\test
\hello
index.php (page for test.mydomain.com/hello)
谢谢。
(对不起,网址中的空格。它不会让我的帖子带有链接)
【问题讨论】:
-
没用:试试这个:app.npham.dk/test vs. app.npham.dk/test
-
1) 我在规则中看不到任何外部重定向,因此原因可能不在规则中。
DirectorySlash On(默认值)可以进行重定向。 2) 我不确定RewriteConds 中的 AND/OR 优先级,所以[OR]标志可能会破坏您的条件。 3)$1后向引用只能在RewriteRule中使用,所以从RewriteCond中删除它并使用%{REQUEST_URI}。
标签: apache .htaccess mod-rewrite subdomain