Html “重写.htaccess以防止用户访问”;索引“;
这是我的.htaccess,我使用了404定制页面和hide.html和.php扩展名。但是当我阻止用户输入.html和.php时,它们也可以访问Html “重写.htaccess以防止用户访问”;索引“;,html,apache,.htaccess,mod-rewrite,Html,Apache,.htaccess,Mod Rewrite,这是我的.htaccess,我使用了404定制页面和hide.html和.php扩展名。但是当我阻止用户输入.html和.php时,它们也可以访问http://example.com/index和子文件夹http://example.com/folder/index。我使用相对url链接图像和资产,用户输入“索引”将使其取消链接。如何使用.htaccess将任何“索引”重定向到/error404.html ErrorDocument 404 /error404.html <IfModul
http://example.com/index
和子文件夹http://example.com/folder/index
。我使用相对url链接图像和资产,用户输入“索引”将使其取消链接。如何使用.htaccess将任何“索引”重定向到/error404.html
ErrorDocument 404 /error404.html
<IfModule mod_rewrite.c>
RewriteCond %{THE_REQUEST} \.(?:html|php)\s [NC]
RewriteCond %{REQUEST_URI} !=/error404.html
RewriteRule ^ - [R=404,L]
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# Remove .html-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/$ $1.html
# End of Apache Rewrite Rules
</IfModule>
ErrorDocument 404/error404.html
RewriteCond%{THE_REQUEST}\.(?:html | php)\s[NC]
重写cond%{REQUEST_URI}=/error404.html
重写规则^-[R=404,L]
选项+FollowSymLinks
重新启动发动机
重写基/
#将尾部斜杠添加到url
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_URI}!(\[a-zA-Z0-9]{1,5}|/|#(.*))$
重写规则^(.*)$$1/[R=301,L]
#从url中删除.php扩展名
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}\.php-f
重写规则^([^\.]+)/$$1.php
#从url中删除.html扩展名
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}\.html-f
重写规则^([^\.]+)/$$1.html
#Apache重写规则结束
我只解了一半。。。。
代码如下:
<Files "index">
RewriteCond %{REQUEST_URI} !=/error404.html
RewriteRule ^ - [R=404,L]
</Files>
这段代码是一种愚蠢的解决方法,但如果我有上千个文件夹,它将非常复杂。我只解决了一半。。。。
代码如下:
<Files "index">
RewriteCond %{REQUEST_URI} !=/error404.html
RewriteRule ^ - [R=404,L]
</Files>
这段代码是一种愚蠢的解决方法,但如果我有上千个文件夹,它将非常复杂。最后,此方法可以将所有“索引”重定向到错误页面,错误为404
RewriteEngine on
RewriteCond %{REQUEST_URI} index
RewriteCond %{REQUEST_URI} !=/error404.html
RewriteRule ^ - [R=404,L]
但加载时出现问题。js和css文件似乎没有链接。使用back方法可以访问js和css文件。最后,此方法可以将所有“索引”重定向到错误404的错误页面
RewriteEngine on
RewriteCond %{REQUEST_URI} index
RewriteCond %{REQUEST_URI} !=/error404.html
RewriteRule ^ - [R=404,L]
但加载时出现问题。js和css文件似乎没有链接。使用back方法可以访问js和css文件