且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

htaccess的重写URL与查询字符串

更新时间:2023-02-23 09:51:38

更新时间:

现在进行测试。试试这个:

Now is tested. Try this:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9-=_?]+)/?$ index.php?filter=$1 [L] 

的.htaccess 的推移在根目录下。

.htaccess goes in root directory.

该请求的URL的 http://www.mysite.com/accounts/ 的,但可以是任何东西: http://www.mysite.com/apples/

The requested URL is http://www.mysite.com/accounts/ but could be anything: http://www.mysite.com/apples/.

注:在地址栏中显示的URL是被列入该地址栏的人。我认为不是的 http://www.mysite.com/index.php?filter=accounts 的,因为我想重定向的目的就是用更友好的一(取代的 HTTP ://www.mysite.com/accounts 的),这是一个具有在地址栏,而不是其他的方式来输入。有点混乱,但我希望这是有道理的。

NOTE: The URL displayed in the address bar is the one that was entered in that address bar. I assume is not http://www.mysite.com/index.php?filter=accounts because I guess the purpose of the redirection is to replace it with a more friendly one (http://www.mysite.com/accounts), which is the one that has to be typed in the address bar, not the other way around. Little confusing but I hope it makes sense.

要进行测试,包括以下内容仅code处的index.php在根目录下。

To test it, include the following only code at index.php in root directory.

<?php 

if ($_GET['filter'] == 'accounts') {
echo "This is Accounts<br /><br />";    
}else {
echo "This is INDEX<br /><br />";       
}

?>

至于在什么地方里面的.htaccess重写规则,我不知道。我猜你面前和实际规则之后尝试一下。

As to where to place the rewrite rules inside .htaccess, I could not know. I guess you have to try it before and after the actual rules.