对URL进行整理失败

时间:2014-06-10 18:10:30

标签: regex apache .htaccess mod-rewrite

所以我有一个网址

  

http://domain.com/directory/

目录中有一个index.php,它允许我访问该URL,因为它是

但是我想要访问http://domain.com/directory/?id=123但是要http://domain.com/directory/123

我在根目录和directory文件夹中都尝试了以下内容,但仍然没有运气

RewriteEngine On
RewriteRule ^directory/([^/]*)$ /directory/?id=$1 [L]

1 个答案:

答案 0 :(得分:1)

将此规则放在/directory/.htaccess

RewriteEngine On
RewriteBase /directory/

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