Apache服務器301重定向去掉.html和.php


在做優化網站的時候,會考慮到網站整站的集權:

考慮到網站可以生成靜態,首先,讓網站優先訪問 index.html

之后考慮:去掉 .html 和 .php。

利用 .htaccess

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]
</IfModule>

修改:

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteBase /
 RewriteCond %{HTTP_HOST} ^www\.yn37wang\.com$ [NC]
 RewriteCond %{REQUEST_URI} ^/index.html [NC]
 RewriteRule .* / [R=301,L]
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]
</IfModule>

即可。

具體:

RewriteEngine On
RewriteBase /

# .htaccess偽靜態301去掉index.html尾巴
RewriteCond %{HTTP_HOST} ^www\.qdonger\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/index.html [NC]
RewriteRule .* / [R=301,L]

# .htaccess偽靜態301去掉index.php尾巴
RewriteCond %{HTTP_HOST} ^www\.qdonger\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/index.php [NC]
RewriteRule .* / [R=301,L]

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM