.htaccess是否从php重定向到html文件?

.htaccess是否从php重定向到html文件?,.htaccess,redirect,.htaccess,Redirect,'尝试创建从php(旧文件)到新html文件的重定向(是的,这种方式)。 如何从index.php重定向到index.htlm文件 情况如下: http://domain.com/ -> http://domain.com/index.html http://domain.com/index.php -> http://domain.com/index.html http://domain.com/?l=ru -> http://domain.com/index.html ht

'尝试创建从php(旧文件)到新html文件的重定向(是的,这种方式)。 如何从index.php重定向到index.htlm文件

情况如下:

http://domain.com/ -> http://domain.com/index.html
http://domain.com/index.php -> http://domain.com/index.html
http://domain.com/?l=ru -> http://domain.com/index.html
http://domain.com/?l= -> http://domain.com/index.html
http://domain.com/index.php?l=ru -> http://domain.com/index.html

http://domain.com/?l=en -> http://domain.com/index_e.html
http://domain.com/index.php?l=en  -> http://domain.com/index_e.html
请,帮助,请,解释为什么你的代码会工作。 Thanx

尝试一下:

RewriteEngine On
RewriteCond %{QUERY_STRING} !(^|&)l=en($|&)
RewriteRule ^/?(index\.php)?$ index.html [L]
RewriteRule ^/?(index\.php)?$ index_e.html [L]

请解释一下为什么你的代码会工作,注意显示你首先尝试的是什么?我使用了:RewriteEngine on并尝试定义RewriteRule一些工作,一些没有,结果伴随500个错误。(遗憾,但没有什么值得展示的;我一点也不擅长写作。htaccess指导。我试图使用上其他帖子的信息。htaccess重定向,但没有成功)非常感谢,Ultimater!如果你有时间,请解释你的代码是做什么的。重写条件与下一个重写规则配对。它检查查询字符串,这意味着URL中的
字符后面的字符串。感叹号的意思是“不”。
(^ |&)l=en($|&)
是一个正则表达式。我们不想匹配像
scroll=end
这样的内容,它包含
l=en
。因此
(^ |&)
匹配字符串的开头或
&
字符。
($|&)
与字符串或
&
字符的结尾匹配。如果条件为true,我们将运行第一条重写规则,然后运行
[L]
,这将使它成为最后一条运行的规则,因此不会读取第二条重写规则。超级!清晰准确!非常感谢你!p、 第一个重写规则的逻辑是它匹配文件路径的开头字符串
^
。后跟
/?
,这是一个可选的斜杠,用于匹配
domain.com
domain.com/
。接下来是
(index\.php)
,它可以选择匹配
index.php
。后跟
$
,表示字符串结束。这样就避免了将请求与所有其他文件(如
/about.html
)匹配并将其重写到错误页面的问题。最后,它会重写为index.html或index_e.html,具体取决于我们的重写条件是否匹配。明天将复制您的评论与朋友共享:)