【问题标题】:mod-rewrite rule for this url此 url 的 mod-rewrite 规则
【发布时间】:2012-09-05 04:28:51
【问题描述】:

请您帮忙为这个网址创建一个模组重写规则

http://localhost/view.php?item_id=28&sef=2009-bristol-blenheim-in-west-yorkshire

我想让它去

http://localhost/view.php?item_id=28

我希望我的链接看起来像这样

http://localhost/view/28/2009-bristol-blenheim-in-west-yorkshire

我目前正在将此规则用于另一个页面

RewriteRule ^category/[!/.]*([A-Za-z]+)/?$ /browse.php?cat=$1    [NC,L]

但似乎无法更新它以适用于这个..

当前 htaccess

RewriteEngine On
Options +FollowSymLinks

# Browse Category
RewriteRule ^category/[!/.]*([A-Za-z]+)/?$ /browse.php?cat=$1    [NC,L]

# View Item
RewriteRule ^view/([0-9]+)/([a-zA-Z0-9-]+)$ /view.php?item_id=$1&sef=$2 [NC]

浏览类别正常,查看项目不正常

【问题讨论】:

  • 您需要清楚您希望访问者能够提供什么 URL,以及您实际希望请求到达的服务器上的什么路径。给出三个路径令人困惑,你能澄清一下吗?

标签: php mod-rewrite


【解决方案1】:

如果你想要这样的请求

http://localhost/view/28/2009-bristol-blenheim-in-west-yorkshire

默默地成为服务器请求

http://localhost/view.php?item_id=28&sef=2009-bristol-blenheim-in-west-yorkshire

然后试试这个:

RewriteRule ^view/([0-9]+)/([a-zA-Z0-9-]+)$ /view.php?item_id=$1&sef=$2 [NC]

【讨论】:

  • 谢谢,但我得到了 404,将使用我的完整 htaccess 文件进行更新
  • 现在已修复,您的规则有效,但我需要添加 Options -Multiviews 以使其通过参数。
猜你喜欢
  • 2011-07-20
  • 1970-01-01
  • 2015-09-22
  • 1970-01-01
  • 1970-01-01
  • 2013-01-13
  • 2020-06-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多