我想通过 .htaccesss 将我的 filename.php 更改为 filename/。
所以,http://labs.ksj-oepites-zomergem.be/info.php#/deleiding 应该变成http://labs.ksj-oepites-zomergem.be/info/#/deleiding
我有什么:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
### To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1\/ [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([-a-zA-Z0-9]+)\/$ $1.php [L]
此代码会将 filename.php 更改为 filename 而不是 filename/
在我的 .htaccess 中使用此代码,我的网站将无法正常工作。 当我在 javascript 中使用 ajax 调用 php 文件时..我收到“意外的 EOF”
有什么建议吗?
最佳答案
重复: hide .php extension - htaccess
答案是: 重写引擎开启
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
这是以下内容的重复: hide .php extension - htaccess
其中有答案: RewriteRule ^(.*)$/$1.php [L]
当隐藏 PHP 时,我倾向于采用后者,并添加了使 .asp、.html、.cfm 和 .jsp 也重写为 .php 的规则,因此查看服务器不应泄露技术。也就是说,除非客户要求,或者我想创建更短/更漂亮的网址,否则我不会隐藏它。
关于javascript - .htaccess 隐藏 .php 文件扩展名,改为显示/(斜杠),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22078890/