如何使用htaccess显示URL中链接的特定参数?

时间:2014-02-17 12:18:46

标签: php .htaccess mod-rewrite

我应该编写What.htaccess代码来转换

localhost/article.php?id=something&number=something 

进入

localhost/article/id

思想家伙?

1 个答案:

答案 0 :(得分:1)

您可以在DOCUMENT_ROOT/.htaccess文件中使用这样的规则:

RewriteEngine On
RewriteBase /

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

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^article/([^/]+)/?$ article.php?id=$1 [L,QSA,NC]