小编jam*_*son的帖子

.htaccess 将所有扩展名重定向到 php

我最近更新了我的.htaccess文件以隐藏网址的.php 扩展名。效果很好,当我尝试访问domain.com/index 时,它会显示 php 文件。

当我输入domain.com/index.php 时,它会将我重定向到domain.com/index url 并显示 .php 文件。

出于安全原因,我想将所有其他扩展名重定向到无扩展名 url 以显示 .php 文件。我的问题是,我无法将.htaccess配置为重定向众所周知的扩展名,如.html .asp。aspx .shtml 等到非扩展 url,并获取 .php 文件显示为内容。

我的 .htaccess 文件如下所示:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# php extension to no extension url
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.+)\.php $1 [R=301,L]


# no extension to the .php file
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

# this is for the …
Run Code Online (Sandbox Code Playgroud)

php http .htaccess redirect apache-2.2

6
推荐指数
1
解决办法
4690
查看次数

标签 统计

.htaccess ×1

apache-2.2 ×1

http ×1

php ×1

redirect ×1