我的.htaccess mod_rewrite出了问题。我做了一个简单的自定义CMS,我把它放在我的域的子目录中; http://www.example.com/cms
我遇到以下情况:
CMS /的index.php?页=模块/页/ index.php的 转换为 CMS /模块/页/索引
和 CMS /的index.php?页=模块/页/ edit.php?ID = 1 转换为 CMS /模块/页/编辑/ 1
我已经使用了子域名,但是当我使用example.com/cms时它没有做任何事情
我做了这个.htaccess但我无法让它工作......
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]
答案 0 :(得分:0)
如果这是在htaccess文件中,则URI的前缀被删除(前导斜杠),因此这些模式将不匹配任何内容。从模式中删除前导斜杠或使其成为可选项(使用?
):
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]