【问题标题】:RewriteRule will not work in .htaccess fileRewriteRule 在 .htaccess 文件中不起作用
【发布时间】:2012-07-06 00:51:02
【问题描述】:

我在 Stack 上发现了几个问题,其中展示了很多示例,但我已经尝试了书中的每个人,但都无法正常工作。

我正在尝试转换。

www.domain.com/title/index.php?id=70048305

www.domain.com/title/70048305

我希望它可以双向转换。当他们使用查询字符串和干净的 url 输入时。

我的重写有什么问题?

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^title/(.+)$ index.php?id=$1 [L,QSA]

请注意,我已将此 .htaccess 文件放在根目录和 /title/ 文件夹中。

【问题讨论】:

  • 你在你的本地主机上尝试吗?当我通常在 localhost 上编辑 .htaccess 时,大约需要 10-15 分钟才能生效。有时甚至会在 apache 上重新启动。

标签: php html .htaccess mod-rewrite redirect


【解决方案1】:

试试这个

RewriteEngine On

RewriteRule ^([a-zA-Z0-9-+/]+)$ index.php?id=$1
RewriteRule ^([a-zA-Z0-9-+/]+)/$ index.php?id=$1

【讨论】:

  • 正确,我回来这里是为了回答我自己的问题。第一个是有效的。
【解决方案2】:

不要匹配^title/(.+)$,你只需要匹配像^title/([\d]+)/?这样的数字

否则,

www.domain.com/title/index.php?id=70048305

将匹配并重定向到:

index.php?id=index.php?id=70048305

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-10
    • 1970-01-01
    • 2015-04-25
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    相关资源
    最近更新 更多