htaccess mod_rewrite-将所有URL重新路由到除/admin外的所有索引 [英] htaccess mod_rewrite - reroute all urls to index except /admin

查看:86
本文介绍了htaccess mod_rewrite-将所有URL重新路由到除/admin外的所有索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在htaccess文件中设置一小套重写规则,我希望每个URL都转到index.php文件,但/admin除外,我想将其重定向到admin.php.不幸的是,对mod_rewrite或regexp不太熟悉.

I'm setting up a small set of rewrite rules in an htaccess file, where I want every url to go to a index.php file except for /admin which I want to redirect to admin.php. Not very familiar with mod_rewrite or regexp unfortunately.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^admin$ admin.php [L]
    RewriteRule . /index.php [L]
</IfModule>

这给了我一个内部服务器错误(不是500).删除或取消注释管理员重写即可使其正常工作.

This gives me an internal server error (not saying 500). Removing or uncommenting the admin rewrite makes it work.

推荐答案

需要将条件应用于index.php重写规则,否则将导致重定向循环. RewriteCond仅适用于紧随其后的RewriteRule,因此将所有内容路由到索引的规则没有条件.尝试只是重新排列行:

The conditions need to be applied to the index.php rewrite rule, otherwise it causes a redirect loop. A RewriteCond only gets applied to the immediately following RewriteRule so the rule that routes everything to index has no conditions. Try just rearranging the lines:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^admin$ admin.php [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

这篇关于htaccess mod_rewrite-将所有URL重新路由到除/admin外的所有索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆