今天我想实现这一点.htaccess会自动从浏览器的url中删除任何类型的文件扩展名。
让我们说比如用户点击一个链接来吸引用户
mylink.php
它应该把他带到那里,但删除.php
我尝试使用一些.htaccess代码,但他们没有做太多。
此外,我可以访问这样的页面
.htaccess代码是
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html
# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
任何人的想法?
答案 0 :(得分:0)
RewriteEngine On
# Change this to the appropriate base (probably just / in your case)
RewriteBase /stackoverflow/9762238/
# Any url that requests a .php file on the base will be redirected to dir with same base name
# The condition is important to prevent redirect loops!
RewriteCond %{ENV:REDIRECT_STATUS} !=200
RewriteRule ^(.*)\.php$ $1/ [R=301,L]
# Requests for directories that do not actually exist will be be translated into php file requests
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+)/$ $1 [L]