htaccess的特定文件夹中的异常 [英] htaccess with specific folder exception

查看:100
本文介绍了htaccess的特定文件夹中的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成立了一个htaccess文件,以便创建一个小的路由结构,其中的URL重定向到的index.php。我想补充一个异常的地方,如果在/ admin的,任何事情在用户类型,网址,而不是重定向到admin.php文件。

I've set up an htaccess file in order to create a small routing structure where urls redirect to index.php. I want to add an exception where if the user types in "/admin" and anything after, the url instead redirects to admin.php.

htaccess的 -

htaccess -

RewriteEngine On
RewriteBase /
RewriteRule ^admin/?(.*)$ admin.php?page=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

例: http://mysite.com/admin/settings/ 应该引起管理。 PHP?页=的设定,而 http://mysite.com/about/ 应导致的index.php(不使用任何参数,在这里)。正则表达式真的不是我的那杯茶,尤其是当有多个条件来考虑。想法?

Example: http://mysite.com/admin/settings/ should lead to admin.php?page=settings, while http://mysite.com/about/ should lead to index.php (not using any parameters here). Regexp is really not my cup of tea, especially when there are multiple conditions to consider. Ideas?

编辑:^管理/([^ /] *)/?解决了它。

^admin/([^/]*)/? solved it.

推荐答案

您可以尝试这在一个.htaccess文件的根目录下:

You may try this in one .htaccess file in root directory:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}   !admin\.php    [NC]
RewriteRule ^admin/([^/]*)/? /admin.php?page=$1  [NC,L]

RewriteCond %{REQUEST_URI}  !/admin/        [NC]
RewriteRule .*              /index.php      [NC,L]

有关永久重定向,替换[NC],L]与[R = 301,NC,L]

For permanent redirection, replace [NC],L] with [R=301,NC,L]

这篇关于htaccess的特定文件夹中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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