Welcome to WebmasterWorld Guest from 52.91.39.106

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Redirect with parameter from subfolder

     
10:56 am on Aug 18, 2011 (gmt 0)

Junior Member from BG 

5+ Year Member

joined:Aug 18, 2011
posts:92
votes: 21


Hi,

I have the following URL to redirect:

http://www.site.com/subfolder/index.php?language=ro


want to redirect to

http://www.site2.com/


I have tried the following:

RewriteCond %{THE_REQUEST} /subfolder/(index\.php)?\?language=(.ro)\ HTTP/
RewriteRule ^(index\.php)?$ [%{HTTP_HOST}...] [R=301,L]

Redirect permanent /subfolder/index.php?language=ro
http://www.site2.com


but it doesn't work.

Any help will be much appreciated.
4:28 pm on Aug 18, 2011 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:15642
votes: 796


Hurrah, I get to paste in my query-string boilerplate after I went to all the trouble of writing it up and stashing in a safe place.
By default, rewrites simply ignore the query string. That is, mod_rewrite stashes the query in a safe place, does its stuff to the part before the question mark, and then reappends the original query.

Changing a Query

#1 To delete a query, add a ? to the end of your rewrite target.
#2 To replace a query--or create a new one--add ?blahblah to the rewrite target. The blahblah can be either literal text, or stuff you captured earlier. (#1 and #2 are really the same thing: you're just replacing the query with either something or nothing.)
#3 To add to an existing query, again put ?blahblah at the end of the target, but also include [QSA] in the bracketed material at the end of the Rule. It stands for "Query String Append", meaning that the blahblah is to be added to the existing query--if any--instead of replacing it.

Getting the Query

You only need to retrieve the original query if
#1 you want the rewrite to behave differently depending on what the query was
or
#2 you need to change or delete the query

Add a Condition that says

RewriteCond %{QUERY_STRING} blahblah


using your ordinary Regular Expressions, anchors and ! as needed.

To test whether there was a query at all

RewriteCond %{QUERY_STRING} .


which simply means "If the query contains at least one character of any kind".

If you need to capture part of the query, use parentheses as usual. In the rewrite target, the capture will be %1, %2 etc instead of $1, $2 etc, because they are coming from a Condition instead of the Rule. Each set is separately numbered, so the first capture in the Rule will still be $1.


Spend some more time fighting with your htaccess and come back in 24 hours.
5:06 pm on Aug 18, 2011 (gmt 0)

Junior Member from BG 

5+ Year Member

joined:Aug 18, 2011
posts:92
votes: 21


Could you please write down the exact code?
8:02 pm on Aug 18, 2011 (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


By using
%2
in the rule target, you are redirecting to /ro on the end of the URL, i.e.
http://www.example.com/ro
which is not the URL you asked about in your question.

By using
%{HTTP_HOST}
in the target, you will redirect to the same domain as the request arrived for, not to "site2". State the actual domain in the rule target.

THE_REQUEST
pattern should begin
^[A-Z]{3,9}\ /subfolder
8:20 pm on Aug 18, 2011 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:15642
votes: 796


Oh, another thing I just noticed.

RewriteRule ^(index\.php)?$

Is that meant to be a literal question mark? If yes, it won't work (see above about query strings).

In your code as written so far, nothing needs to be captured. It's a straight AAA to BBB redirect.
8:24 pm on Aug 18, 2011 (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


No. It means it redirects both
example.com/index.php
and
example.com/
requests.

The parentheses are not for capturing, but to specify the scope of the optional part defined by the question mark.
4:42 am on Aug 19, 2011 (gmt 0)

Junior Member from BG 

5+ Year Member

joined:Aug 18, 2011
posts:92
votes: 21


Thanks for the advices.
I just want to redirect any query in which there is the parameter ?language=ro to my new site. I have already asked in some other forums about the exact code to try, but there is no any result. I think .htaccess redirecting is really hard to understand. I'm looking for the simpliest way of doing it.
5:47 am on Aug 19, 2011 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:15642
votes: 796


No. It means it redirects both example.com/index.php and example.com/ requests.

Check. Just making sure.

RewriteCond %{QUERY_STRING} blahblah 

That's the part you need to look at.

I think .htaccess redirecting is really hard to understand. I'm looking for the simpliest way of doing it.

Everyone is :) But you have to use the safest and most effective way, even if it isn't the simplest.
8:01 am on Aug 19, 2011 (gmt 0)

Junior Member from BG 

5+ Year Member

joined:Aug 18, 2011
posts:92
votes: 21


I found the solution:

Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /subfolder/

RewriteCond %{REQUEST_URI} ^/subfolder/index.php$
RewriteCond %{QUERY_STRING} ^language=ro$
RewriteRule ^.*$ [site2.com?...] [L,R=301]

Thanks for the help.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members