虚荣URL无效

时间:2015-03-21 10:16:51

标签: php .htaccess mod-rewrite

我正在使用htaccess尝试重写网址。我已经尝试了大约10个版本的代码和示例,但没有任何改变。我知道mod_rewrite正在运行,因为它正在向网址添加www,但虚荣网址无法正常工作。

RewriteRule ^franchise/([0-9]+)/?$ franchise-information.php?franchiseid=$1    [NC,L]    # Handle product requests

这是.htaccess文件:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
  RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  RewriteRule ^franchise/([0-9]*?)/$ franchise-information.php?franchiseid=$1 [NC,L]
</IfModule>

这是网址:

http://www.playballkids.com/franchise-information.php?franchiseid=162

1 个答案:

答案 0 :(得分:0)

您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

Options -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} /franchise-information\.php\?franchiseid=([^\s&]+) [NC]
RewriteRule ^ franchise/%1? [R=302,L,NE]

RewriteRule ^franchise/(\d+)/?$ franchise-information.php?franchiseid=$1 [NC,L,QSA]