[英]How to remove .php extension only for file after the first slash?
I am trying to remove the .php extension only from the file after the first slash. 我试图仅在第一个斜杠后从文件中删除.php扩展名。
Right now I have: 现在我有:
example.com/file.php/123123
example.com/file.php/123123
What I want is: 我想要的是:
example.com/file/123123
example.com/file/123123
I have tried adding this code to the .htaccess file 我尝试将此代码添加到.htaccess文件中
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(e)/?$ /$1.php [L,NC]
It successfully removes the .php extension but only for the last part of the URL. 它成功删除了.php扩展名,但仅删除了URL的最后一部分。 Meaning it reads:
意思是:
example.com/file/123123
example.com/file/123123
as: 如:
example.com/file/123123.php
example.com/file/123123.php
and then makes it unable to load because there is no 123123.php. 然后由于没有123123.php而使其无法加载。
How can I make it so it only tries to remove the .php from the after the first slash? 我该怎么做,以便它仅尝试从第一个斜杠后删除.php? Thanks
谢谢
If you have mod_rewrite
module installed and enabled, you can paste the following code into your apache2.conf
file: 如果已安装并启用了
mod_rewrite
模块,则可以将以下代码粘贴到apache2.conf
文件中:
<Directory /path/to/site/folder>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [R,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]
</IfModule>
</Directory>
This module can be installed by default, so you can just try with this code. 默认情况下可以安装此模块,因此您可以尝试使用此代码。 It may work.
它可能会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.