2017-03-01 25 views
0

我现在有这在我的WordPress htaccess文件:如何针对所有的.html URLS除了index.html的htaccess的

<IfModule mod_rewrite.c> 
 
     RewriteEngine On 
 
     RewriteBase/
 
     RewriteRule ^index\.html?$/[NC,R,L] 
 
     RewriteEngine On 
 
     RewriteBase/
 
     RewriteRule ^index\.php$ - [L] 
 
     RewriteCond %{REQUEST_FILENAME} !-f 
 
     RewriteCond %{REQUEST_FILENAME} !-d 
 
     RewriteRule . /index.php [L] 
 
    </IfModule> 
 

 
    #RedirectMatch 301 (.*)\.html$ $1/

我想重定向所有.HTML只是在没有任何文件扩展名的网址,即www.example.com/about.html到www.example.com/about/。

代码工作得很好,在/index.html重定向到/

上面的注释代码(RedirectMatch 301 (.*)\.html$ $1/)应重定向的.html工作的漂亮的URL,但它也做了index.html的地方,而不是将其重定向到/它将其重定向到/ index

有没有一种方法可以让我压缩我的代码并执行我正在尝试执行的操作?

回答

0

有这样的:

RewriteEngine On 
RewriteBase/

RewriteRule ^index\.html?$/[NC,R,L] 

# redirect every .html except index.html 
RewriteRule ^(?!index\.html$)(.+)\.html?$ /$1 [NC,R,L] 

RewriteRule ^index\.php$ - [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
相关问题