如何为文件夹重写Url?

时间:2015-03-09 13:38:43

标签: php .htaccess url-rewriting

我需要重写下面的链接

www.website.com/folder1/folder2/index.php?name=value

是这样的:

www.website.com/folder1/folder2/name/

我用这行代码尝试了htaccess,但它没有用。

RewriteEngine on RewriteRule ^name/([A-Za-z0-9-]+)/?$ index.php?name=$1 [NC,L]

提前谢谢!

1 个答案:

答案 0 :(得分:0)

/folder1/folder2/.htaccess

中插入此规则
RewriteEngine On
RewriteBase /folder1/folder2/

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

RewriteRule ^name/([A-Za-z0-9-]+)/?$ index.php?name=$1 [NC,QSA,L]