javascript - .htaccess 隐藏 .php 文件扩展名,改为显示/(斜杠)

标签 javascript php .htaccess

我想通过 .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/

相关文章:

javascript - 显示从 1 到 n 的所有数字,从 1 到 1 递增,其中 n 由用户在提示时输入

javascript - 使用 JavaScript 确定一个月中的天数的最佳方法是什么?

.htaccess - 如何使用 .htaccess 重写此 url

.htaccess - 我可以强制 .htaccess 刷新吗?

.htaccess - htaccess 仅在文件不存在时重写

javascript - 如何将事件监听器添加到 Google Chart 的 PieChart 的特定部分(数据栏)?

javascript - 使用 Bing SDS 进行地理围栏

php - Laravel Scout - 观察关系

php - MediaWiki python 端口?

php - 必须捕获所有数量最多的产品