【问题标题】:dyanmic url not rewriting ht access动态 url 不重写 htaccess
【发布时间】:2015-07-23 20:27:17
【问题描述】:

我所有的重写都没有一个。当用户搜索时,我希望 URL 在 url 栏中正确显示。

Options +FollowSymLinks
RewriteEngine on
RewriteBase /website/

RewriteCond %{THE_REQUEST} /search\?c=([^&\s]+)&s=([^&\s]+)&mincost=([^&\s]+)&maxcost=([^&\s]+)&sort_by=([^&\s]+)&colour=([^&\s]+) [NC]

RewriteRule ^search/%1/%2/%3/%4/%5/%6? [L,R]

RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ product.php?id=$1&c=$2&name=$3&page=$4 [L,QSA]

RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)/?$ product.php?id=$1&c=$2&name=$3 [L,QSA]

RewriteRule ^search/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ search.php?c=$1&s=$2&mincost=$3&maxcost=$4&sort_by=$5&colour=$6&page=$7 [L,QSA]

RewriteRule ^search/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ search.php?c=$1&s=$2&mincost=$3&maxcost=$4&sort_by=$5&colour=$6 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php [L]

/website/search/category/all/100/500/low-to-high/any-color

(进入网址栏时有效)

/website/search?c=category&s=all&mincost=100&maxcost=500&sort_by=low-to-high&colour=any-color

(在使用过滤器和提交表单时显示)- 我需要这个 url 显示为:

/website/search/category/all/100/500/low-to-high/any-color

【问题讨论】:

  • 搜索form action="/website/search"

标签: php .htaccess mod-rewrite


【解决方案1】:

您的第一个 RewriteRule 不正确。替换为:

RewriteCond %{THE_REQUEST} /search\?c=([^&\s]+)&s=([^&\s]+)&mincost=([^&\s]+)&maxcost=([^&\s]+)&sort_by=([^&\s]+)&colour=([^&\s]+) [NC]
RewriteRule ^ search/%1/%2/%3/%4/%5/%6? [L,R=302,NE]

注意^search之间的空格

【讨论】:

  • 如果我已经在搜索页面上并搜索,答案有效,如果我在家里(也有一个搜索表单转到/website/search)并使用相同的参数搜索它没有
  • 规则与您的导航无关。只要准确 example.com/website/search?c=category&s=all&mincost=100&maxcost=500&sort_by=low-to-high&colour=any-colour URL 结构进入网络服务器,它就可以工作。
  • 好的,我必须检查为什么会发生这种情况,现在我在 localhost 上运行它,一旦上传到一个域,我不想在域名后面加上 /website/,我会简单地删除 RewriteBase /website/ ?
  • 是的,只需将其替换为 RewriteBase /
猜你喜欢
  • 2011-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-02
  • 2014-07-09
  • 2021-10-21
相关资源
最近更新 更多