[英]Htaccess Rewrite Rule with Page Not Found issue
htaccess question on rewrite rules htaccess的重写规则问题
I have 3 files in my folder 我的文件夹中有3个文件
create.php
index.html
index.php
and I got this as my .htaccess for rewrite rules 我把它作为重写规则的.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]
The issue is I want to access the site 问题是我要访问该网站
http://member.mydomain.com/admin/permissions/create
But it tell me 但这告诉我
The requested URL /admin/create.php was not found on this server.
Is there something wrong with my .htaccess , the rewrite rule is mainly for index.php to do its query sending, I would like my create.php to be accessible with the path of 我的.htaccess是否有问题,重写规则主要用于index.php进行查询发送,我希望我的create.php可以通过以下路径访问
http://member.mydomain.com/admin/permissions/create
Thanks !! 谢谢 !!
Updated .htaccess 更新的.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]
But it return same error 但它返回相同的错误
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.
On your code you have only: 在您的代码上,您只有:
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
However just that does not take into account weather or not the file actually exists or not before redirecting, you want something like: 但是,这只是没有考虑到天气或文件在重定向之前是否实际存在或不存在,您需要执行以下操作:
# Resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/admin/$1\.php -f
RewriteRule /([^/]+)/?$ $1.php [L]
You would also need to place this rule at the top of your rules. 您还需要将此规则放在规则的顶部。
This is the entire set of rules: 这是整个规则集:
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]
Your do nothing rule is not required. 您无需执行任何操作规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.