301使用空格和查询字符串重定向URL [英] 301 redirect URL with spaces and query string

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

问题描述

我在这样的页面中有一些hrefs:



I had some hrefs in a page like this:

<a href="cities/Social Security Lawyer in Ann Arbor">Ann Arbor</a>





我已将它们更改为此(带连字符):





I''ve changed them to this (with hyphens):

<a href="cities/Social-Security-Lawyer-in-Ann-Arbor">Ann Arbor</a>





这是在我的htaccess文件中(第一部分中的连字符是新的):



This is in my htaccess file (the hyphen in the first part is new):

RewriteRule ^cities/([a-zA-Z.\ -]+)/?$ cities.php?city=$1 [NC,L]





两种情况下一切正常。当我的hrefs有空格时,我得到了正确的页面和内容。在我将连字符添加到hrefs并将其添加到RewriteRule后也工作正常。



所有这些都需要的页面是cities.php当然,查询字符串是Social-Security-Lawyer-in-Ann-Arbor。



现在,我需要在htaccess做一些事情所以如果访问者保存了以前没有连字符的URL,我可以将它们重定向到带有连字符的正确页面/查询字符串。



我尝试了以下上面的其他RewriteRule但它不起作用





Everything works fine in both cases. When my hrefs had the spaces, I got to the correct page and content. After I added the hyphens to the hrefs and added it to the RewriteRule that worked fine also.

The page that''s called for all of this is cities.php and of course the query string is the "Social-Security-Lawyer-in-Ann-Arbor" for example.

Now, I need to do something in htaccess so that if the visitor has saved a previous URL without the hyphens, I can redirect them to the correct page/query string with the hyphens.

I tried the following above the other RewriteRule but it doesn''t work

RewriteRule ^Social%20Security%20Lawyer%20in%20Ann%20Arbor$ http://www.mysite.com/cities/Social-Security-Lawyer-in-Ann-Arbor  [R=301,L]



有人有什么建议吗?



2013-03-04 - 这个页面似乎有答案,但我不知道如何将它应用到我的特定情况: Apache .htaccess查询字符串重定向 [ ^ ]

推荐答案

cities.php?city =
cities.php?city=


1 [NC,L]





两种情况下一切正常。当我的hrefs有空格时,我得到了正确的页面和内容。在我将连字符添加到hrefs并将其添加到RewriteRule后也工作正常。



所有这些都需要的页面是cities.php当然,查询字符串是Social-Security-Lawyer-in-Ann-Arbor。



现在,我需要在htaccess做一些事情所以如果访问者保存了以前没有连字符的URL,我可以将它们重定向到带有连字符的正确页面/查询字符串。



我尝试了以下上面的其他RewriteRule但它不起作用





Everything works fine in both cases. When my hrefs had the spaces, I got to the correct page and content. After I added the hyphens to the hrefs and added it to the RewriteRule that worked fine also.

The page that''s called for all of this is cities.php and of course the query string is the "Social-Security-Lawyer-in-Ann-Arbor" for example.

Now, I need to do something in htaccess so that if the visitor has saved a previous URL without the hyphens, I can redirect them to the correct page/query string with the hyphens.

I tried the following above the other RewriteRule but it doesn''t work

RewriteRule ^Social%20Security%20Lawyer%20in%20Ann%20Arbor


http://www.mysite.com/cities/Social-Security-Lawyer-in-Ann-Arbor [R = 301,L]
http://www.mysite.com/cities/Social-Security-Lawyer-in-Ann-Arbor [R=301,L]



有没有人有任何建议?



2013-03-04 - 这个页面似乎有答案,但我不知道如何应用它我的具体情况: Apache .htaccess查询字符串重定向 [ ^ ]


这篇关于301使用空格和查询字符串重定向URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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