【问题标题】:URL rewrite for dynamic websites动态网站的 URL 重写
【发布时间】:2017-07-08 06:46:56
【问题描述】:

我正在尝试重写我的动态 URL,这里有一些关于它的信息。

整个数据来自单个表,没有创建其他表。 URL 重写在 Apache 服务器上处于活动状态。

我的当前网址

http://www.example.com/list.php?city=Mumbai&business_category=Accounting+services

预期网址

http://www.example.com/Mumbai/Accounting-services

我的代码

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$    list.php?city=$1&business_category=$2    [NC,L]    # Process product requests

【问题讨论】:

  • 其实看起来不错。究竟是什么不工作?
  • 我的 URL 没有发生任何事情,它保持原样。
  • 你是否期望当前的url在进入地址栏时被转换成预期的url?
  • 当你在点击提交按钮后选择城市和业务类别时,你会得到当前的 URL 我希望它变成预期的 URL。
  • 好的。那么它与htaccess无关。您需要更改表单的action 属性。然后您的 htaccess 已经设置为可以处理它。

标签: php apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

您可以尝试以下方法 - 我认为它或多或少是您所追求的

RewriteCond %{THE_REQUEST} /(?:list\.php)?\?city=([^&\s]+)&business_category=([^&\s]+) [NC]
RewriteRule ^ %1/%2? [R=302,L,NE]

【讨论】:

  • 我不认为他想要重定向。
  • 什么也没找到,但这里是返回 URL example.com/home/wwwexample/Kalyan/Accounting+services
  • 我想要的是,如果我喜欢使用商业类别在我的城市中的某些东西,我会使用我当前的 url 得到它,但我希望它像其他 url www.example.com/(selected city)/ 一样显示(选定的业务类别),结果我得到了结果列表。
猜你喜欢
  • 1970-01-01
  • 2018-06-25
  • 2012-07-25
  • 2016-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多