htaccess的重写URL与查询字符串 [英] .htaccess Rewrite URL with a query string

查看:310
本文介绍了htaccess的重写URL与查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经试过一吨张贴于计算器,但没有解决方案,似乎为我工作。我想重写我的网站的几个网址是搜索引擎友好。

I have tried a ton of solutions posted at stackoverflow but nothing seems to work for me. I would like to rewrite a few URLs on my site to be search engine friendly.

我想这样的一个网址: - http://www.mysite.com/index.php?filter=accounts 为了尽可能显示: - http://www.mysite.com/accounts

I would like a URL like this:- http://www.mysite.com/index.php?filter=accounts To display as:- http://www.mysite.com/accounts

很多各地的网络帖子给这个作为解决方案: -

A lot of posts around the web give this as the solution:-

RewriteRule ^([^/]+)/?$ index.php?filter=$1 [QSA,L]

但是,这并不做任何事情。

But this doesn't do anything.

我的网站是一个Joomla CMS的网站,已经有.htaccess文件中的某些重写。难道说我把我的新重写规则是放错了地方?

My site is a Joomla CMS site and there are already some rewrites within the .htaccess file. Could it be that I am putting my new RewriteRule is the wrong place?

下面是不加我的新重写规则完整的.htaccess文件

Here is the full .htaccess file without my new RewriteRule added

Options +FollowSymLinks
RewriteEngine On

# prevents people from accessing anything with phpMyAdmin
RewriteRule phpMyAdmin - [F]

# force canonical www if request is for non-www or has port number etc
RewriteCond %{HTTP_HOST} !^(www\.mysite\.com)?$
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteBase /
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

任何帮助将是非常美联社preciated。 : - )

Any help would be much appreciated. :-)

推荐答案

更新时间:

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

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.

这篇关于htaccess的重写URL与查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆