root index.php上的重写规则

时间:2015-01-05 19:39:26

标签: apache .htaccess mod-rewrite rewrite

我正在尝试仅在根index.php文件上重写url。我不想为任何目录重写url。 我在htaccess中使用它,它的工作就像index.php的重写一样好。 我查看了stackoverflow,如果这个帖子已经存在,我没有看到它。

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

谢谢!

1 个答案:

答案 0 :(得分:2)

为了能够仅在根目录中执行此规则,您可以使用此规则:

DirectoryIndex index.php
RewriteEngine On

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

正则表达式[^/]+将确保与根目录不匹配。

相关问题