Welcome to WebmasterWorld Guest from 54.197.168.70

Forum Moderators: Ocean10000 & incrediBILL & phranque

Need some help with a rewrite rule

   
4:03 pm on Jan 8, 2012 (gmt 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)

10+ Year Member



Hi mudloop

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

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



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)

10+ Year Member



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)



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)

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



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.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month