我目前正在使用mod_rewrite,但想要一个特定的网址路径来使用子域名。使用mod_rewrite可以做到这一点吗
当前URL如下所示:
http://domain.com/index.php?wiki/index/ -> http://domain.com/forum/wiki如何才能将url设置为
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]发布于 2012-01-07 15:10:20
这是一个基于mod_rewrite的解决方案,只需在您的.htaccess文件中放入以下行:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^forum/wiki/?$ http://wiki.domain.com/forum/ [R=301,L,NC]这会将http://domain.com/forum/wiki重定向到http://wiki.domain.com/forum/
发布于 2012-01-07 15:02:04
这里有个提示:实际上你不需要做重定向。
只要有一个处理这两个域的one vhost即可。
只需进行内部重写,它就会正常工作。
这是我自己的vhost (它处理domain.com和所有*.domain.com)和你想要的东西(这可能不是100%工作,但嘿,我在这之后给你两个提示)的混合:
<VirtualHost *>
ServerAdmin webmaster@domain.fr
DocumentRoot "/web/htdocs/domain/prod/website"
ServerName domain.com
ServerAlias *.domain.com
ErrorLog "/web/logs/domain.error.log"
CustomLog "|/opt/httpd/bin/rotatelogs /web/logs/domain/access_log.%Y-%m-%d-%H_%M_%S.log 5M" combined
# your RewriteRules ()
RewriteEngine On
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/domain.rewrite.log"
RewriteLogLevel 9
# Your RewriteRules ()
RewriteCond %{HTTP_HOST} ^wiki.domain.com$
RewriteRule ^/forum/(.*) /wiki/index.php?wiki/index$1 [QSA,L]
</VirtualHost>两个提示:
如果您不在托管环境中(=如果它是您自己的服务器,并且您可以修改虚拟主机,而不仅仅是.htaccess文件),请尝试使用RewriteLog指令:它可以帮助您跟踪以下问题:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On我最喜欢用来检查regexp的工具:
http://www.quanetic.com/Regex (别忘了选择ereg(POSIX)而不是preg(PCRE)!)
https://stackoverflow.com/questions/8766963
复制相似问题