htaccess的特定文件夹中的异常异常、文件、夹中、htaccess

2023-09-02 11:27:52 作者:雨蚀

我已经成立了一个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]