更改html页面的URL

时间:2016-07-17 13:10:02

标签: html .htaccess mod-rewrite

我正在尝试将html页面的网址更改为

  1. example.com/intraday.html 至example.com/intraday。
  2. example.com/economic_calendar.html example.com/economiccalendar
  3. 我正在尝试使用.htaccess文件,但它无法正常工作

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^\ ]+)\.html
    RewriteRule ^ /%2/ [L,R=301]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/(.*?)/?$
    RewriteCond %{DOCUMENT_ROOT}/%1.html -f
    RewriteRule ^ /%1.html [L] 
    

    任何建议。

1 个答案:

答案 0 :(得分:1)

https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^/]+)/?$ $1.html

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)([^/]+)/?$ $1_$2.html [L]