正确.htaccess

时间:2015-11-07 08:42:35

标签: php .htaccess

请在这种情况下帮助我。

我有一个共享主机,我想以良好的方式调整我的.htaccess文件。 我有以下页面:

  1. index.html
  2. news.html
  3. 类似post-01-11-2015.html
  4. 的网页

    现在我想:

    1. 删除所有网址末尾的所有.html
    2. 如果当前页面为index.html,我想看到example.com,而不是example.com/index.html
    3. 当我在页面post-01-11-2015.html中打开news.html时,我想在浏览器网址中看到example.com/posts/2015/11/01
    4. 当我输入example.com/posts/2015/11/01时,我想看到页面post-01-11-2015.html
    5. 你建议我做的任何事,都很好。
    6. 如果您需要任何信息,请告诉我。

      现在有了这个模块代码,但我收到错误cycle redirection

      <IfModule mod_rewrite.c>
           RewriteEngine on
           RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
           RewriteRule ^(.*) http://%1/$1 [R=301,L]
      
           RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
           RewriteRule ^index\.html$ http://www.example.com [R=301,L]
      
           RewriteRule ^post-(\d+)-(\d+)-(\d+)\.html$ /posts/$1/$2/$3 [R=301,L,NC]
           RewriteRule post-(\d+)-(\d+)-(\d+)\.html$ posts/$1/$2/$3 [R=301,L,NC]
      
           RewriteRule (.+)\.html$ /$1 [R=301,L,NC]
      
           RewriteCond %{REQUEST_FILENAME} !-f
           RewriteCond %{REQUEST_FILENAME} !-d
           RewriteRule . /index.html [L,QSA]
      
      </IfModule>
      

      非常感谢你!希望你帮助我最好的方式!

1 个答案:

答案 0 :(得分:0)

将您的htaccess更改为:

RewriteBase /
RewriteRule ^/$ index.html [QSA,L]
RewriteRule ^post/([0-9_-]+)/([0-9_-]+)/([0-9_-]+)/$ post-$3-$2-$1.html [QSA,L]