Welcome to WebmasterWorld Guest from 54.198.15.59

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

How to drop the query from URL

     
2:16 pm on Mar 6, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


Hi all

I am still struggling with a previous issue, I have decided to try and catch the problem on the new site as everything I tried on the old site has failed

I am using this

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?num=4
RewriteRule (.*) [newdomain.co.uk...] [R=301,L]

The walks folder has a rewrite rule

RewriteRule ^([^./]+)$ /walks/walk.php?title=$1 [L]

The browser address bar still shows

[newdomain.co.uk...]

I would like it to show

[newdomain.co.uk...]

How can I drop the query from the end?
2:35 pm on Mar 6, 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


Use example.com in the forum to stop URL auto-linking.

Add a question mark to the end of the target URL to clear the query string.

Post your new code here for checking.
2:48 pm on Mar 6, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


Use example.com in the forum to stop URL auto-linking


Sorry, forgot

? added works as it should now many thanks g1smd

Is there a reason why it wouldn't work like that from the old sites htaccess, I did try that if you remember, hence I gave up and served the correct content but with the wrong URL formation
3:20 pm on Mar 6, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


mmm still have an issue, the individual walks work fine but now I am trying the same thing for the town name

folder/?town=Town_Name

Its 1 level up and thats the URL its going to, do I do it in root htaccess or in that folders htaccess file. Do I put it before my rewrite?
3:30 pm on Mar 6, 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


Since redirects tell the user agent to make a new request for a new URL, redirects must always be listed before rewrites.

The rewrite is actually going to fetch the content from inside the server. It is too late to change the URL once the server is reading the hard drive. Attempting to do a redirect after a rewrite simple exposes the server internal filepath (the one you wnated to keep secret) back out on to the web as a URL.

You will also run into this problem if a URL request results in a redirect performed by the .htaccess in a folder and a rewrite performed by the .htaccess in the root. The rewrite will happen first. Never put any redirects into the .htaccess file in any folder. Put all redirects in the root .htaccess and with their RegEx patterns adjusted to suit.
3:59 pm on Mar 6, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


Ok making huge progress now, that works too

But just found an issue with the first one, the old URL's just have numbers 1 to 30

The issue: anything with a 1 example 1, 11, 17 all get caught by the first one which is 1 I know why, but when I setup that db I was green to using 01, 02 etc, is there a way to stp this happening.

11 to 19 get caught as number 1
4:10 pm on Mar 6, 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


Without seeing the code you're looking at, no way to comment.
4:14 pm on Mar 6, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


Here it is

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?num=1
RewriteRule (.*) http://www.example.com/walks/Walk_Name? [R=301,L]

But if ?num=11 num=1 gets used
AND
if num=20 num=2 gets used
5:21 pm on Mar 6, 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


Yes, "num=1" says "begins with 1".

Use the $ for "num=1$" meaning ends with "num=1", but this does not allow for there to be further parameters in the URL request.

A soft anchored pattern like "&?num=1&?" may also work.

The alternative is to list the 10 entry before the 1 entry and the 20 entry before the 2 entry. That is foolproof.