RewriteRule重命名带有参数的URL不起作用

时间:2019-04-11 08:45:18

标签: php .htaccess mod-rewrite

我想要这个网址:  http://www.website.com/article?a=article-id

成为此网址: http://www.website.com/article-id

我尝试了以下代码:

RewriteEngine On
RewriteRule ^([^/]*)\$ /article?a=$1 [L]

我也尝试过:

RewriteRule ^([a-z-/]+)$ article?a=$1 [QSA]

没有工作。

Thx

这是我在.htaccess处的代码

AddHandler application/x-httpd-php54 .php .php5 .php4 .php3  

RewriteEngine On
RewriteCond %{HTTP_HOST} ^bepo\.co.il$ [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [L,R=301]

errorDocument 404 http://www.website.com

Options -Indexes


RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]

1 个答案:

答案 0 :(得分:0)

请尝试以下重写:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^\/article$
RewriteCond %{QUERY_STRING} ^a=(.*)
RewriteRule ^(.*)$ /%1? [L,QSA]