簡體   English   中英

將.htaccess代碼粘貼到WordPress htaccess代碼之上還是之下?

[英]Paste .htaccess code above or below the WordPress htaccess code?

我需要在.htaccess文件中添加一些代碼。 但是我不清楚將其粘貼到哪里,因為我的.htaccess文件中包含WordPress代碼。

代碼A:Wordpress代碼

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

有人可以告訴我在哪里插入“ CODE B”(見下文)嗎? 應該在WordPress .htaccess代碼之上還是之下? 如果應該放在上面,我是否需要從Wordpress代碼中刪除RewriteEngine On並將其放在最頂部? 請回復代碼,以便我可以直觀地看到執行此操作的正確方法。

代碼B:我的代碼

#Specify IP Allowed to Login
<Files wp-login.php>
order deny,allow
deny from all
allow from 12.345.67.890
</Files>

代碼C:以下.htaccess順序正確嗎? 如果沒有,您能告訴我正確的訂單嗎? RewriteEngine On是否應該在頂部附近?

Options +FollowSymLinks

#Specify IP Allowed to Login
<Files wp-login.php>
order deny,allow
deny from all
allow from 12.345.67.891
</Files>

#STRONG HTACCESS PROTECTION
<Files ~ "^.*\.([Hh][Tt][Aa])">
 order allow,deny
 deny from all
 satisfy all
</Files>

<files wp-config.php>
Order allow,deny
Deny from all
</files>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

#Prevent directory browsing
Options All -Indexes

#Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

#Redirect index.html
RewriteCond %{THE_REQUEST} ^.*/index.html [NC]
RewriteRule ^(.*)index.html$ http://www.domain.com/$1 [R=301,L]

#Redirect IP Address
RewriteCond %{HTTP_HOST} ^123\.456\.789\.999$
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

#Force Trailing Slash
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.domain.com/$1/ [L,R=301] 

#Stop Hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)domain.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|bmp|zip|rar|mp3|flv|swf|xml|php|png|css|pdf)$ - [F]

與其嘗試使用<Files>指令,不如將現有的WP .htaccess與另一個具有類似效果的重寫規則結合使用:

#STRONG HTACCESS PROTECTION
<Files ~ "^.*\.([Hh][Tt][Aa])">
  order allow,deny
  deny from all
</Files>

<files wp-config.php>
  Order allow,deny
  Deny from all
</files>

Options All -Indexes
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

#Redirect index.html
RewriteCond %{THE_REQUEST} ^.*/index.html [NC]
RewriteRule ^(.*)index.html$ http://www.domain.com/$1 [R=301,L]

#Redirect IP Address
RewriteCond %{HTTP_HOST} ^123\.456\.789\.999$
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

#Force Trailing Slash
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.domain.com/$1/ [L,R=301] 

#Stop Hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)domain.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|bmp|zip|rar|mp3|flv|swf|xml|php|png|css|pdf)$ - [F]

# only allow 12.345.67.890 IP to access /wp-login.php or /wp-admin/
RewriteCond %{THE_REQUEST} /(wp-login\.php|wp-admin/) [NC]
RewriteCond %{REMOTE_ADDR} !=12.345.67.890
RewriteRule ^ - [F]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM