我想重写一个网址 我的网站内容只有html页面,所以它很简单
内在张力结构:
[/]
---[visit]
------index.html
---[...]
---index.html
原来是:
www.example.com/visit
我想重写网址并将其显示在地址栏中,如下所示
https://example.com/visit-italy-in-summer/
我正在使用以下规则
RewriteEngine On
RewriteBase /
## Redirect all to https non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
## Redirecd index.html & php to /
RewriteCond %{THE_REQUEST} /index\.(html|php) [NC]
RewriteRule ^(.*?)index\.(?:html|php)$ /$1 [R=301,NC,NE]
RewriteRule visit-italy-in-summer visit [R=301]
一切都很完美,除非我访问
https://example.com/visit-italy-in-summer
浏览器地址栏显示
https://example.com/visit
答案 0 :(得分:0)
你最后的规则是相反的,它应该是:
RewriteCond %{THE_REQUEST} /visit[/\s?] [NC]
RewriteRule ^ visit-italy-in-summer [R=301,L,NC]
RewriteRule ^visit-italy-in-summer/?$ visit/ [L,NC]
清除浏览器缓存后进行测试。