如何使用的.htaccess隐藏我的.html和扩展名为.php?
问题描述:
我有这样的.htaccess:
I have this .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z,0-9,A-Z,_-]+)$ ./$1.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z,0-9,A-Z,_-]+)$ ./$1.html
现在的问题是:它只是hidding的.php 难道不应该隐瞒的.php和.html?
The problem is: Its just hidding .php Shouldn't it hide .php and .html?
答
1 / HTML文件仍然可以访问,因为你的第二组规则永远不会被使用。此外,你的第二个行专门告诉服务器离开真正的文件放在一边。
1./ your html files are still accessible because your second set of rule will never be used. Besides, your second line specifically tells the server to leave "real" files aside.
2,/你只需要RewriteEngine叙述上一次。
2./ You only need RewriteEngine On once .
3 /你应该使用标志时,停下来告诉你重写。
3./ You should use the flags to tell your rewriting when to stop.
RewriteEngine On
# if the requested file does not exist
RewriteCond %{REQUEST_FILENAME} !-f
# if the requested folder does not exist
RewriteCond %{REQUEST_FILENAME} !-d
# sends all urls except home to its corresponding php file
RewriteRule ^([a-z,0-9,A-Z,_-]+)$ ./$1.php [R=301,L]
但如果你想让它的所有文件扩展名的工作,删除第一条规则,只留下。
But if you want it to work for all file extensions, remove the first rule, leaving only.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z,0-9,A-Z,_-]+)$ ./$1.php [R=301,L]