.htaccess设置获取“/”后的值作为GET变量

时间:2014-01-14 13:49:46

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

示例考虑http://example.com/abcdef

我希望将其更改为http://example.com/?id=abcdef

如何做到这一点?

2 个答案:

答案 0 :(得分:1)

将此代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On
RewriteBase /uppit/

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

答案 1 :(得分:0)

RewriteEngine On # Turn on the rewriting engine 
RewriteBase /
RewriteRule ^/?$ index.php?id=$1 [NC,L]