htaccess - 将哑网重定向到工作网址

时间:2018-02-26 14:55:13

标签: php apache .htaccess centos7 httpd.conf

我有以下隐藏.htaccess扩展名的.php文件。也就是说,它不是显示http://address/info.php,而是显示http://address/info

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# 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
RewriteRule ^ %{REQUEST_URI}.php [L]

htaccess文件中,我需要添加phpinformation(这是一个愚蠢的链接 - 不会去任何地方:http://address/phpinformation)重定向到info。也就是说,http://address/phpinformation需要重定向到http://address/info

我应该如何修改代码?

1 个答案:

答案 0 :(得分:0)

你能试试吗

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteCond %{REMOTE_ADDR} ^192\.168\.1\.120 
RewriteRule ^phpinformation\.php /info.php [R,NC,L] 
RewriteBase / 
## hide .php extension 
# 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 
RewriteRule ^ %{REQUEST_URI}.php [L]