我正在本地开发一个应用程序(在域名 <!> lt; mydomain <!> gt; .dev 下)。

为了使用友好的网址,我已经设置了我的.htaccess:

RewriteEngine on
# Externally redirect to add missing trailing slash
RewriteRule ^(([a-z0-9._\-]+/)*[a-z0-9_\-]+)$ http://example.com/$1/?%{QUERY_STRING}[NC,R,L]
RewriteRule ^about/$ about.php [NC,L]
RewriteRule ^issues/$ issues.php [NC,L]
RewriteRule ^issue/([a-z0-9_\-]+)/$ issue.php?slug=$1 [NC,L]

SetEnv PHP_VER 5
IndexIgnore *
Options +FollowSymLinks

工作正常。令人讨厌的是,当上网时,它并不是那么好:

http://example.com/issue/my-slug/#23不返回GET变量。为什么呢?

有帮助吗?

解决方案

我的猜测,基于过去的经验是RewriteBase,可能是因为你在共享服务器上,或者其他一些非标准配置。

RewriteEngine on

#Set base as doc root.
RewriteBase /

# Externally redirect to add missing trailing slash
RewriteRule ^(([a-z0-9._\-]+/)*[a-z0-9_\-]+)$ http://mydomain.eu/$1/?%{QUERY_STRING}[NC,R,L]
RewriteRule ^about/$ about.php [NC,L]
RewriteRule ^issues/$ issues.php [NC,L]
RewriteRule ^issue/([a-z0-9_\-]+)/$ issue.php?slug=$1 [NC,L]

SetEnv PHP_VER 5
IndexIgnore *
Options +FollowSymLinks

其他提示

我没看到

RewriteRule ^(([a-z0-9._\-]+/)*[a-z0-9_\-]+)$ http://mydomain.eu/$1/?%{QUERY_STRING}[NC,R,L]

应匹配该URL,但这是唯一一个带有[R]标志的URL来进行外部重定向。尝试评论该行,以确保您的应用程序的其他部分没有进行重定向。我猜是有。

替换URL和标志之间缺少一些空格。您还可以按如下方式简化第一条规则:

RewriteRule ^([a-z0-9._-]+/)*[a-z0-9_-]+$ %{REQUEST_URI}/ [NC,R=301,L]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top