公共.htaccess重写规则

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了公共.htaccess重写规则相关的知识,希望对你有一定的参考价值。

Please, be careful with trailing slash rewrite as post requests without a trailing slash will be ignored.

Be sure to test if you plan on using that one.
Not compatible with Drupal.
  1. ## no-www redirect
  2. RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
  3. RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  4.  
  5. ## www redirect
  6. RewriteCond %{HTTP_HOST} ^example.com [NC]
  7. RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
  8.  
  9. ## multiple domain redirect
  10. RewriteCond %{HTTP_HOST} !^example.com$ [NC]
  11. RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
  12.  
  13.  
  14. ## trailing slash
  15. ## BE EXTRA CAREFUL WITH THIS ONE!
  16. ## POST REQUESTS WITHOUT TRAILING SLASH
  17. ## WILL BE IGNORED!
  18. RewriteCond %{REQUEST_FILENAME} !-f
  19. RewriteCond %{REQUEST_FILENAME} !-d
  20. RewriteCond %{REQUEST_URI} !(.*)/$
  21. RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

以上是关于公共.htaccess重写规则的主要内容,如果未能解决你的问题,请参考以下文章

htaccess 单参数重写规则

htaccess 列出目录并为其重写规则

.htaccess 重写规则破坏 css

htaccess 重写规则 404 错误

htaccess 子域重写规则

PHP/Apache:用 .htaccess 重写规则