.htaccess 重定向 php 到 html 并且我还想添加除英语之外的语言标志
.htaccess redirect php to html and also I want add language flag except to English
以上规则是将.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
例子
我想要的是印地语索引
- 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/ will not redirect to http://www.example.com/en
- 英文网站将保持 http://www.example.com
- http://www.example.com/ equals to http://www.example.com/
- http://www.example.com/?lang=en equals to http://www.example.com/
RewriteCond %{REQUEST_FILENAME} =-f
RewriteRule ^(.*)\.php$ .html [NC,L]
RewriteRule ^(.*)\.html$ .php [NC,L]
RewriteRule ^(.*).html$ .php? [QSA]
RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1.html [L,R=301]
您可以使用这些规则:
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$ /.php [L]
#############################
#language redirection
#1) /?lang=hi as /hi (for hompage)
RewriteRule ^hi/?$ /?lang=hi [L,NC]
#for html pages
RewriteRule ^hi/(.+)\.html$ /.html?lang=hi [L,NC]
确保在测试这些规则之前清除浏览器缓存。
当您对规则感到满意时将 R 更改为 R=301 以使重定向永久化并缓存浏览器。
以上规则是将.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
例子 我想要的是印地语索引 - 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/ will not redirect to http://www.example.com/en - 英文网站将保持 http://www.example.com - http://www.example.com/ equals to http://www.example.com/ - http://www.example.com/?lang=en equals to http://www.example.com/
RewriteCond %{REQUEST_FILENAME} =-f
RewriteRule ^(.*)\.php$ .html [NC,L]
RewriteRule ^(.*)\.html$ .php [NC,L]
RewriteRule ^(.*).html$ .php? [QSA]
RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1.html [L,R=301]
您可以使用这些规则:
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$ /.php [L]
#############################
#language redirection
#1) /?lang=hi as /hi (for hompage)
RewriteRule ^hi/?$ /?lang=hi [L,NC]
#for html pages
RewriteRule ^hi/(.+)\.html$ /.html?lang=hi [L,NC]
确保在测试这些规则之前清除浏览器缓存。
当您对规则感到满意时将 R 更改为 R=301 以使重定向永久化并缓存浏览器。