jam*_*son 6 php http .htaccess redirect apache-2.2
我最近更新了我的.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 index
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
小智 0
如果没有其他“.” 在您的文件中,除了扩展名之外,您是否尝试用任何字符串替换“.php”?
# php extension to no extension url
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.\s+\sHTTP/.+
RewriteRule ^(.+)\.php $1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)