mod_rewrite的正确语法?

时间:2016-08-22 10:10:42

标签: apache .htaccess mod-rewrite apache2.4

在Apache 2.4.7 .htaccess文件中使用的正确语法是什么

http://www.example.com/go/stuff

重写为:

http://www.example.com/index.php?tab=go&page=stuff

我在RewriteCondRewriteRule指令中使用什么语法?

1 个答案:

答案 0 :(得分:1)

您可以在网站root .htaccess中尝试此规则:

RewriteEngine On

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?tab=$1&page=$2 [L,QSA]