使用 Mod_Rewrite 子域转发到 URL?
我目前正在使用 mod_rewrite,但希望使用特定的 URL 路径来使用子域名。这可以通过 mod_rewrite
实现吗?
目前 URL 是这样的:
http://domain.com/index.php?wiki/index/ -> http://domain.com/forum/wiki
How can I get the url to be
http://wiki.domain.com/forum/
当 wiki 目录不存在时, ?我不断收到 403 错误,因为该目录不存在,因此它是被禁止的。我目前有:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^wiki.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^wiki.domain.com$
RewriteRule ^(.*)$ http://domain.com/wiki/index[R=301,L]
I'm currently using mod_rewrite but would like a specific URL path to use a subdomain name. Would this be possible with mod_rewrite
?
Currently the URL is like this:
http://domain.com/index.php?wiki/index/ -> http://domain.com/forum/wiki
How can I get the url to be
http://wiki.domain.com/forum/
when the wiki directory does not exist? I keep getting a 403 as the directory does not exist and so it's forbidden. I currently have:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^wiki.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^wiki.domain.com$
RewriteRule ^(.*)$ http://domain.com/wiki/index[R=301,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个基于 mod_rewrite 的解决方案,只需将这些行放入您的 .htaccess 文件中:
这会将
http://domain.com/forum/wiki
重定向到http://wiki.domain .com/forum/
Here is a solution based on mod_rewrite, just put these lines in your .htaccess file:
This will redirect
http://domain.com/forum/wiki
tohttp://wiki.domain.com/forum/
提示如下:您实际上不需要进行重定向。
只需拥有一个处理两个域的虚拟主机即可。
只需进行内部重写即可。
这是我自己的虚拟主机(处理
domain.com
和所有*.domain.com
)和你想要的(这个可能无法 100% 工作,但是嘿,我在此之后给您两个提示):两个提示:
如果您不在托管环境中(= 如果它是您自己的服务器,并且您可以修改虚拟主机,而不仅仅是
. .htaccess
文件),尝试使用RewriteLog
指令:它可以帮助您追踪此类问题:我最喜欢的检查正则表达式的工具:
http://www.quanetic.com/Regex (不要忘记选择 ereg(POSIX) 而不是 preg(PCRE)!)
Here's the tip: you don't need to do a redirect actually.
Just have one vhost that handles both domains.
Just do an internal rewrite, and it will work.
Here's a mix of my own vhost (that handles
domain.com
and all*.domain.com
) and what you'd like (this may not work 100% but hey I give you two hints after this):Two hints:
If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the
.htaccess
files), try to use theRewriteLog
directive: it helps you to track down such problems:My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)