Php htaccess问题

Php htaccess问题,php,.htaccess,templating,Php,.htaccess,Templating,我制作了一个PHP框架,它有一个内置的TPL系统。它获取url的结尾,并查找包含该字符串的文件。因此,如果url是http://website.com/tagHereTpl系统将查找名为tagHere.php的文件。这一切都很好,但我现在正试图扩展框架,使其具有内置的后端面板。我试过多种方法,但都不管用 我决定看看Wordpress的htaccess,因为它们正是我想要实现的。以下是他们的htaccess的工作原理 它们检查请求的文件名是否为文件。如果它不是一个文件,那么他们会检查它是否是一个文

我制作了一个PHP框架,它有一个内置的TPL系统。它获取url的结尾,并查找包含该字符串的文件。因此,如果url是
http://website.com/tagHere
Tpl系统将查找名为
tagHere.php的文件。这一切都很好,但我现在正试图扩展框架,使其具有内置的后端面板。我试过多种方法,但都不管用

我决定看看Wordpress的htaccess,因为它们正是我想要实现的。以下是他们的htaccess的工作原理

它们检查请求的文件名是否为文件。如果它不是一个文件,那么他们会检查它是否是一个文件夹。如果它不是文件夹,它们将重定向到index.php。我希望它检查它是否是一个文件/文件夹,如果不是,则从URL中删除.php标记,以便TPL系统可以获取指定的文件并返回它

这是我的原始.htaccess文件

RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1`
<ifmodule mod_rewrite.c="">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</ifmodule>
这是Wordpress的原始.htaccess文件

RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1`
<ifmodule mod_rewrite.c="">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</ifmodule>

重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
以下是我的尝试:

<ifmodule mod_rewrite.c="">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]
RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1
</ifmodule>

重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
重写规则^(|/)$index.php?url=$1
重写规则^([a-zA-Z0-9_-]+)(|/)$index.php?url=$1
当我尝试上面的htaccess时,它返回404错误。

规则

RewriteRule . /index.php [L]
将始终匹配每个URL,因为它表示“如果URL中有字符,则重定向”

你要找的是这样的东西:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^admin/(.*?)$ admin.php?location=$1 [L]
RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1
规则

RewriteRule . /index.php [L]
将始终匹配每个URL,因为它表示“如果URL中有字符,则重定向”

你要找的是这样的东西:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^admin/(.*?)$ admin.php?location=$1 [L]
RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1

仍然返回404错误。不知道为什么。。。但我相信这是htaccess,而不是PHP。如果没有所有的代码,很难帮助您。您正在尝试什么URL以及结果应该是什么?我正在尝试访问此-->它应该返回HTML网页。仍然返回404错误。不知道为什么。。。但我相信这是htaccess,而不是PHP。如果没有所有的代码,很难帮助您。您正在尝试什么URL以及结果应该是什么?我正在尝试访问此-->它应该返回一个HTML网页。