【发布时间】:2013-02-16 00:36:42
【问题描述】:
我最近更新了我的 .htaccess 文件以隐藏 URL 的 .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 index
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
【问题讨论】:
标签: php html apache .htaccess redirect