。htaccess将php重定向到html,我也想添加除英语之外的语言标记

问题描述 投票:0回答:1

以上规则是将.php替换为.html。最近,我为该网站添加了另一种语言。当浏览器地址栏中存在/?lang = hi时,该网站现在正在运行中文。

下面的示例有点丑陋:-http://www.example.com/?lang=hi-http://www.example.com/about-us.html?lang=hi-http://www.example.com/contact-us.html?lang=hi

示例我想要的是Hindhi索引-http://www.example.com/?lang=hi等于http://www.example.com/hi-http://www.example.com/about-us.html?lang=hi等于http://www.example.com/hi/about-us.html-http://www.example.com/contact-us.html?lang=hi等于http://www.example.com/hi/contact-us.html

http://www.example.com/不会重定向到http://www.example.com/en-英文网站仍为http://www.example.com-http://www.example.com/等于http://www.example.com/-http://www.example.com/?lang=en等于http://www.example.com/

RewriteCond %{REQUEST_FILENAME} =-f
RewriteRule ^(.*)\.php$ $1.html [NC,L]
RewriteRule ^(.*)\.html$ $1.php [NC,L]
RewriteRule ^(.*).html$ $1.php? [QSA]
RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1.html [L,R=301]
.htaccess mod-rewrite friendly-url
1个回答
0
投票

您可以使用这些规则:

RewriteEngine on


#Redirect php to html
#This will redirect and rewrite your php files to html
#redirect file.php to file.html
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule .+ /%1.html [L,R,NE]
#Rewrite file.html to file.php
RewriteCond %{REQUEST_FILENAME} ^(.+)\.html$
RewriteCond %1.php  -f
RewriteRule ^(.+)\.html$ /$1.php [L]
#language redirection
#1) /?lang=hi as /hi (for hompage)
RewriteRule ^hi/?$ /?lang=hi [L,NC]
#for html pages
RewriteRule ^hi/(.+)\.html$ /$1.html?lang=hi [L,NC]

当您对规则满意时,将R更改为R = 301以使重定向永久化并缓存浏览器。

© www.soinside.com 2019 - 2024. All rights reserved.