2017-06-21 6 views
1

私の.htaccessは404のカスタマイズページを使い、.htmlと.php拡張子を隠しています。しかし、ユーザー入力.htmlと.phpを防止すると、http://example.com/indexとサブフォルダhttp://example.com/folder/indexも参照できます。私は画像とassestsをリンクする相対URLを使用し、ユーザーの入力 "インデックス"はリンクを解除します。 .htaccessを使用して "index"を/error404.htmlにリダイレクトする方法.htaccessを書き直してユーザの訪問を防ぐindex "

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> 

答えて

0

私はちょうどそれを解決するには、半分.... コードはここにある:それはちょうどhttp://example.com/indexで働く

<Files "index"> 
RewriteCond %{REQUEST_URI} !=/error404.html 
RewriteRule^- [R=404,L] 
</Files> 

、のみ、ルートディレクトリに働く別のサブフォルダのために、それが動作していません。誰でも良い答えがありますか?

UPDATE:

<Files "index"> 
RewriteCond %{REQUEST_URI} !=/error404.html 
RewriteRule^- [R=404,L] 
</Files> 
<Files "folder/index"> 
RewriteCond %{REQUEST_URI} !=/error404.html 
RewriteRule^- [R=404,L] 
</Files> 

このコードはsloveする愚かな方法ですが、私は、フォルダの数千を持っている場合、それは非常に複雑になります。

0

最後に、このメソッドはエラー404

RewriteEngine on 
RewriteCond %{REQUEST_URI} index 
RewriteCond %{REQUEST_URI} !=/error404.html 
RewriteRule^- [R=404,L] 

しかしhttp://example.com/負荷何かが間違ってエラーページにすべての「インデックス」をリダイレクトすることができます。 jsとcssファイルはリンク解除のようです。バック愚かなメソッドを使用してjsとcssファイルにアクセスすることができます。

関連する問題