mod_rewrite :为什么它在本地工作而不是在线工作?

发布于 2024-07-18 14:57:58 字数 667 浏览 11 评论 0原文

我正在本地开发一个应用程序(在域名 .dev下)。

为了使用友好的 url,我已经像这样设置了 .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 变量。 为什么?

I'm developing an app locally (under Domain name <mydomain>.dev).

In order to work with friendly urls, i've set up my .htaccess like this:

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

It works fine. Annoyingly, when going online, it's not so great:

http://example.com/issue/my-slug/#23 returns no GET variable. Why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七婞 2024-07-25 14:57:58

我的猜测,根据过去的经验是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

My guess, based on past experience is RewriteBase, likely because your on a shared server, or some other non-standard configuration.

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
青衫负雪 2024-07-25 14:57:58

我不认为它

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

应该与该 URL 匹配,但这是唯一一个带有 [R] 标志的用于执行外部重定向的 URL。 尝试注释掉该行,以确保应用程序中没有其他部分执行重定向。 我的猜测是有的。

I don't see that

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

should match that URL, but thats the only one with the [R] flag to do an external redirect. Try commenting that line out, to make sure there is not some other part of your application doing the redirect. My guess is that there is.

不甘平庸 2024-07-25 14:57:58

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

RewriteRule ^([a-z0-9._-]+/)*[a-z0-9_-]+$ %{REQUEST_URI}/ [NC,R=301,L]

There is some whitespace missing between the substitution URL and the flags. You can also simplify your first rule as follows:

RewriteRule ^([a-z0-9._-]+/)*[a-z0-9_-]+$ %{REQUEST_URI}/ [NC,R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文