Htaccess重写规则与页面未找到的问题


Htaccess Rewrite Rule with Page Not Found issue

关于重写规则的问题

我的文件夹中有3个文件

create.php
index.html
index.php

我把这个作为我的。htaccess重写规则

DirectoryIndex index.php
RewriteEngine On
RewriteBase /admin/
RewriteRule ^([^/]+)/([^/]+)/?$ permissions/index.php?action=$1&id=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

问题是我想访问这个网站

http://member.mydomain.com/admin/permissions/create

但是它告诉我

The requested URL /admin/create.php was not found on this server.

我的。htaccess是否有问题,重写规则主要是为index.php做查询发送,我希望我的create.php可以访问

的路径
 http://member.mydomain.com/admin/permissions/create

! !

. htaccess更新

DirectoryIndex index.php
RewriteEngine On
RewriteBase /admin/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1'.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^([^/]+)/([^/]+)/?$ permissions/index.php?action=$1&id=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

但是它返回相同的错误

Not Found
The requested URL /admin/permissions/create was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

在你的代码中你只有:

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

但是,在重定向之前,只是不考虑文件是否实际存在,你想要这样做:

# Resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/admin/$1'.php -f
RewriteRule /([^/]+)/?$ $1.php [L]

您还需要将此规则放在规则的顶部

这是整个规则集:

Options +FollowSymLinks -MultiViews
DirectoryIndex index.php
RewriteEngine On
RewriteBase /admin/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/admin/$1'.php -f
RewriteRule /([^/]+)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?action=$1&id=$2 [L,QSA]

你的什么都不做规则不需要