获取变量显示在子子目录重写,mod_rewrite

时间:2015-07-21 07:48:57

标签: php .htaccess


我的网站链接是domain.com/index?page=projects

这是我的.htaccess:

Options +FollowSymLinks -Multiviews

<IfModule mod_rewrite.c>

    SetEnv HTTP_MOD_REWRITE On
    RewriteEngine on
    RewriteBase /

    RewriteCond %{THE_REQUEST} ^\w+\ /(.*)\.php(\?.*)?\ HTTP/
    RewriteRule ^ http://%{HTTP_HOST}/%1 [R=301]

    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule .* $0.php


</IfModule>


我想将变量作为子目录转换 像这样:domain.com/index/projects或domain.com/projects
怎么做?
感谢

1 个答案:

答案 0 :(得分:1)

更改规则,使其如下所示:

RewriteCond %{THE_REQUEST} ^\w+\ /(.*)\.php(?:\?page=([^&\ ]+)|)\ HTTP/
RewriteRule ^ http://%{HTTP_HOST}/%1/%2? [R=301,L]

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)/([^/]+)$ $1.php?page=$2 [L]

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)$ $1.php [L]