在做优化网站的时候,会考虑到网站整站的集权:
考虑到网站可以生成静态,首先,让网站优先访问 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]