Forum Moderators: phranque

Message Too Old, No Replies

Escape + redirect: ?

         

anjx

10:14 pm on May 22, 2011 (gmt 0)

10+ Year Member



Hello guys,
I am having problems with dual link since I installed a component on joomla sef. So I have many link that going to the same destination:

myurl.com/page-59.html
myurl.com/page-59.html?start=150
myurl.com/page-59.html?start=375

now I would insert a redirect in the .htaccess to make sure the unique link:

myurl.com/page-59.html

Can you help me please? Thanks

g1smd

12:55 pm on May 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use a RewriteRule to detect the path part and add a preceding RewriteCond looking at %{QUERY_STRING} for the query string part. Capture the page number in a backreference for use by the rule target.

It's two lines of code. What have you tried so far? There are also several thousand similar examples in this forum.

anjx

4:04 pm on May 23, 2011 (gmt 0)

10+ Year Member



Hi g1smd, thank you for your answer. I tried many codes, but I have always failed. My last try:

RewriteRule ^page-([0-9]).html?start=([0-9])$ page-$1.html [R=301]

But I know that it is a wrong code. Please can you give me an exactly code? I do not know what to do.

Thanks

g1smd

6:41 pm on May 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use a RewriteRule to detect the path part. RewriteRule can see only the PATH. It cannot see the query string. Do not include the query string in the pattern.

Add a preceding RewriteCond looking at %{QUERY_STRING} for the query string part. Capture the page number in a backreference for use by the rule target.

The target URL will need the protocol and domain name and the flags will be [R=301,L].

It's TWO lines of code.

anjx

7:19 pm on May 23, 2011 (gmt 0)

10+ Year Member



RewriteCond %{QUERY_STRING} !-f
RewriteRule ^page-([0-9]).html?start=([0-9])$ page-$1.html [R=301,L]

It's correct?

g1smd

7:24 pm on May 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule CANNOT see query strings (the question mark and all after it). Do not quote the query string in the RewriteRule pattern.

Put the query string to be tested as the RewriteCond pattern.

RewriteRule will test only the path part of the URL request.

anjx

7:45 pm on May 23, 2011 (gmt 0)

10+ Year Member



Excuse me, if you tell me the instruction without sintax, I will never understand. Can give me the "TWO lines of code" please? I would be grateful

anjx

8:56 pm on May 23, 2011 (gmt 0)

10+ Year Member



RewriteCond %{QUERY_STRING} start=([a-zA-Z]*)
RewriteRule ^page-([0-9]).html?start=([0-9])$ page-$1.html [R=301,L]

It's correct?

g1smd

9:03 pm on May 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You're getting closer. The RewriteCond line is correct if "start" in the query string consists of letters or words (no digits, no punctuation).

Do not include the query string in the RewriteRule pattern.

The target URL will need the protocol and domain name added.

[edited by: g1smd at 9:27 pm (utc) on May 23, 2011]

anjx

9:16 pm on May 23, 2011 (gmt 0)

10+ Year Member



RewriteCond %{QUERY_STRING} start=([0-9])
RewriteRule ^page-([0-9]).html$ http://www.example.com/page-$1.html [R=301,L]

It's correct?

g1smd

9:26 pm on May 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It looks almost right.

Add a question mark right after the .html to clear the query string value then go test it.

Try single digit page numbers first, then double digit, or more.

anjx

9:40 pm on May 23, 2011 (gmt 0)

10+ Year Member



I have an error..."FORBIDDEN"

g1smd

9:53 pm on May 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use the Live HTTP Headers extension for Firefox to check the headers being sent by the server and the HTTP status codes.

Check the URL shown in the browser address bar.

anjx

10:19 pm on May 23, 2011 (gmt 0)

10+ Year Member



I have change the position and now the home page is working, but when try redirect I have this error:

This page is not redirecting properly Firefox has detected that the server is redirecting the request for this page so that it can never be completed. This problem is often caused by the blocking or rejection of cookies.

anjx

11:46 pm on May 23, 2011 (gmt 0)

10+ Year Member



I have print the result:
[imageshack.us...]

g1smd

12:26 am on May 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Add a question mark on the end of the .html at the end of the target URL (just before the [R=301,L] part).

anjx

7:48 am on May 24, 2011 (gmt 0)

10+ Year Member



greaaaaaaaaaat...I have put the "?" and a "+" and now work :D

RewriteCond %{QUERY_STRING} start=([0-9])
RewriteRule ^page-([0-9]+).html$ http://www.example.com/page-$1.html? [R=301,L]

Thank you :)

anjx

7:50 am on May 24, 2011 (gmt 0)

10+ Year Member



If i would like rewrite also "?start=" without number, can I insert in the same rule?

RewriteCond %{QUERY_STRING} start=([0-9]), start=
RewriteRule ^page-([0-9]+).html$ http://www.example.com/page-$1.html? [R=301,L]

g1smd

5:52 pm on May 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In the RewriteCond change
([0-9])
to
([0-9]*)


In the RewriteRule change
([0-9]+)
to
([0-9]*)


In the RewriteRule pattern change " . " to " \. " too.

anjx

7:59 pm on May 24, 2011 (gmt 0)

10+ Year Member



Thank you very much :)

g1smd

9:28 pm on May 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This thread may have been long-winded but hopefully you now understand what the code actually does.

A thorough read of a guide to Regular Expressions should now be high on your list of priorities.

anjx

10:44 am on May 26, 2011 (gmt 0)

10+ Year Member



Yes, I'm agree :P

Another question if you can help me:
now I would like redirect all page: example:

myurl.com/page-59.html?start=150
to
myurl.com/page-59.html
AND
myurl.com/category/page-57.html?start=400
to
myurl.com/category/page-57.html
AND
myurl.com/category2/page-11.html?start=375
to
myurl.com/category2/page-11.html

Can you help me please..

I think:
RewriteCond %{QUERY_STRING} start=([0-9])
RewriteRule ^page-([0-9]*)\.html$ (.*)/page-$1.html? [R=301,L]

It's wrong?
Thanks

anjx

12:11 pm on May 26, 2011 (gmt 0)

10+ Year Member



Wait...maybe:

RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^([0-9a-zA_Z]*)/page-([0-9]*)\.html$ [myurl.com...] [R=301,L]
RewriteRule ^page-([0-9]*)\.html$ [myurl.com...] [R=301,L]

g1smd

6:34 pm on May 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond affects only the SINGLE RewriteRule that follows.

Do you need the RewriteCond to be duplicated for the second rule?

The second rule can never run because the first rule will match all requests, as the first ' * ' matches zero or more.

You might need to change the rule order OR change the ' * ' to ' + '.

Use example.com to stop the forum auto-linking your URLs.

anjx

7:48 pm on May 26, 2011 (gmt 0)

10+ Year Member



RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^page-([0-9]*)\.html$ [myurl.com...] [R=301,L]
RewriteRule ^([0-9a-zA_Z]*)/page-([0-9]*)\.html$ [myurl.com...] [R=301,L]

it's ok now? :/

g1smd

7:56 pm on May 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Test it with a variety of URLs, both valid and non-valid, both canonical and non-canonical.

Look carefully at the results by using the Live HTTP Headers extension for Firefox.

Use example.com in the forum.

anjx

10:35 pm on May 26, 2011 (gmt 0)

10+ Year Member



I try this but is not working:

RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^page-([0-9]*)\.html$ http://www.example.com/page-$1.html? [R=301,L]
RewriteRule ^([0-9]*)/page-([0-9]*)\.html$ http://www.example.com/page-$1.html? [R=301,L]

If I go in http://www.example.com/page-5.html?start=400 working OK
so
http://www.example.com/page-5.html

but if I go in subcategory:
http://www.example.com/category/page-5.html?start=400
the redirect is wrong and I have:
http://www.example.com/category/page-category.html

anjx

10:41 pm on May 26, 2011 (gmt 0)

10+ Year Member



RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^page-([0-9]*)\.html$ http://www.example.com/page-$1.html? [R=301,L]
RewriteRule ^([0-9a-zA_Z]*)/page-([0-9]*)\.html$ http://www.example.com/$1/page-$2.html? [R=301,L]

Not working

g1smd

11:45 pm on May 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The second rule generates an infinite redirect loop when
http://www.example.com/<something>/page-<nnn>.html

is requested. Do you need for the second rule to have some sort of attached RewriteCond? It currently has none.

The second rule also allows exactly
http://www.example.com//page-.html
to be a valid URL as ' * ' means "ZERO or more".

Add a blank line AFTER each RewriteRule line so you can see what code goes together.

anjx

7:27 am on May 27, 2011 (gmt 0)

10+ Year Member



I have 7 categories and all have pagination with page-5.html?start=400 bug. So I need to delete in the all pages ?start=400 e redirect to page-"number".html
This 31 message thread spans 2 pages: 31