Welcome to WebmasterWorld Guest from 54.147.26.192

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Need some help with a rewrite rule

     
4:03 pm on Jan 8, 2012 (gmt 0)

New User

joined:Jan 8, 2012
posts: 2
votes: 0


Hi,

In a product I was involved in that recently shipped, there was an incorrect url. I'd like to solve it with a rewrite rule.

The incorrect url is as follows :
http://domain/connect/connect/etc


So it has /connect in there twice, though it should only be in there once. So I'd need a rewrite rule that removes one of them, but I don't know regex well enough to do it myself (been years since I dabbled with it).

Thanks a lot!
5:06 pm on Jan 8, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 7, 2003
posts:383
votes: 0


Hi mudloop

rewriterule ^connect/connect/(.*) connect/$1 [L,R=301]
5:41 pm on Jan 8, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


The redirect target should also include the protocol and hostname.

This redirect must be placed before any non-www/www redirect code.

Both of these things avoid introducing an unwanted multiple step redirection chain.
6:33 pm on Jan 8, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 7, 2003
posts:383
votes: 0


Hi mudloop

rewriterule ^connect/connect/(.*) http://hostname/connect/$1 [L,R=301]

Is what g1smd means.

[edited by: engine at 9:56 am (utc) on Jan 10, 2012]
[edit reason] fixed formatting [/edit]

3:10 am on Jan 10, 2012 (gmt 0)

New User

joined:Jan 8, 2012
posts: 2
votes: 0


Thanks for the reply. It's not functioning as it should though, but I suspect rewrite has been disabled on the server. I've asked the administrator, waiting for his reply.
Curious, what does the [L,R=301] part mean?
5:05 am on Jan 10, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12709
votes: 244


It means you need to do some background reading [httpd.apache.org]. Really.

What happens when you say

RewriteEngine On
RewriteRule ^connect/(connect/.*) http://www.example.com/$1 [L,R=301]

? "Not functioning as it should" implies that it is functioning in some other way. Which is always interesting.

Notice how by capturing the second "connect" I have sneakily saved typing eight characters in the target. It is not necessary to do it this way.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members