0

I'm having a problem with my .htaccess mod_rewrite. I've made a simple custom CMS and i've put this in a sub directory of my domain; http://www.example.com/cms

I've got the following situations:

cms/index.php?page=modules/pages/index.php convert to cms/modules/pages/index

and cms/index.php?page=modules/pages/edit.php?id=1 convert to cms/modules/pages/edit/1

I've got it working with a subdomain, but when i use example.com/cms it doesn't do anything

i've made this .htaccess but i couldn't get it working...

RewriteEngine On
Options +FollowSymlinks
RewriteBase /


RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]



RewriteRule ^(.*?)$ $1 [L]

RewriteRule ^/cms/([^/]*)/$ cms/index.php?page=$1 [L,QSA]
RewriteRule ^/cms/([^/]*)$ /cms/index.php?page=$1 [L,QSA]
RewriteRule ^/cms/pages/([^/]*)/$ /cms/index.php?page=pages/$1 [L,QSA]
RewriteRule ^/cms/pages/([^/]*)$ /cms/index.php?page=pages/$1 [L,QSA]
RewriteRule ^/cms/modules/([^/]*)/([^/]*)/$ /cms/index.php?page=modules/$1/$2 [L,QSA]
RewriteRule ^/cms/modules/([^/]*)/([^/]*)$ /cms/index.php?page=modules/$1/$2 [L,QSA]
RewriteRule ^/cms/modules/([^/]*)/([^/]*)/([^/]*)$ /cms/index.php?page=modules/$1/$2&id=$3 [L,QSA]
4

1 回答 1

0

如果这是在 htaccess 文件中,则 URI 的前缀将被删除(前导斜杠),因此这些模式不会匹配任何内容。从模式中删除前导斜杠或使其可选(使用 a ?):

RewriteRule ^/?cms/([^/]*)/$ cms/index.php?page=$1 [L,QSA]
RewriteRule ^/?cms/([^/]*)$ /cms/index.php?page=$1 [L,QSA]
RewriteRule ^/?cms/pages/([^/]*)/$ /cms/index.php?page=pages/$1 [L,QSA]
RewriteRule ^/?cms/pages/([^/]*)$ /cms/index.php?page=pages/$1 [L,QSA]
RewriteRule ^/?cms/modules/([^/]*)/([^/]*)/$ /cms/index.php?page=modules/$1/$2 [L,QSA]
RewriteRule ^/?cms/modules/([^/]*)/([^/]*)$ /cms/index.php?page=modules/$1/$2 [L,QSA]
RewriteRule ^/?cms/modules/([^/]*)/([^/]*)/([^/]*)$ /cms/index.php?page=modules/$1/$2&id=$3 [L,QSA]

此外,您的第一条规则可以简化为:

RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule ^ - [L]
于 2013-05-08T21:28:21.773 回答