带有两个属性的友好URL?

时间:2016-07-01 08:05:52

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

我正在尝试重写一个使用两个属性的丑陋URL。例如,我想example.com/stories/?url=how-are-you?num=5成为example.com/stories/how-are-you/5我已经重写了第一个属性,但我没有知道如何重写num属性。这是我的.htaccess文件:

RewriteEngine On
RewriteBase /stories/

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?url=$1 [L,QSA]

1 个答案:

答案 0 :(得分:1)

尝试:

RewriteEngine On
RewriteBase /stories/

RewriteCond %{THE_REQUEST} /\?url=([^&\s]+)&num=([0-9]+) [NC]
RewriteRule ^ %1/%2? [L,R=302]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?url=$1&num=$2 [L,QSA]