.htaccess将php重定向到html,并且我希望添加除英语之外的语言标志

.htaccess将php重定向到html,并且我希望添加除英语之外的语言标志,.htaccess,mod-rewrite,friendly-url,.htaccess,Mod Rewrite,Friendly Url,上面的规则是将.php替换为.html。最近,我为网站添加了另一种语言。 浏览器地址栏中存在/?lang=hi时,网站现在运行中文 下面的例子有点难看: - - - 范例 我想要的是Hindhi的索引 -等于 -等于 -等于 不会重定向到 -英文网站将保持原样 -等于 -等于 您可以使用以下规则: RewriteEngine on ############################## #Redirect php to html #This will redirect and rew

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

下面的例子有点难看: - - -

范例 我想要的是Hindhi的索引 -等于 -等于 -等于

不会重定向到 -英文网站将保持原样 -等于 -等于


您可以使用以下规则:

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,以使重定向永久并缓存浏览器。

这是您的答案,我想:@Dilek它不起作用,我遵循了上面的url。我想我需要改变一些东西,因为上面的.htaccess代码在vanilla php框架上使用。
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]