homepage Welcome to WebmasterWorld Guest from 50.17.86.12
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
How to drop the query from URL
wheelie34

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4277426 posted 2:16 pm on Mar 6, 2011 (gmt 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?

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4277426 posted 2:35 pm on Mar 6, 2011 (gmt 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.

wheelie34

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4277426 posted 2:48 pm on Mar 6, 2011 (gmt 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

wheelie34

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4277426 posted 3:20 pm on Mar 6, 2011 (gmt 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?

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4277426 posted 3:30 pm on Mar 6, 2011 (gmt 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.

wheelie34

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4277426 posted 3:59 pm on Mar 6, 2011 (gmt 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

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4277426 posted 4:10 pm on Mar 6, 2011 (gmt 0)

Without seeing the code you're looking at, no way to comment.

wheelie34

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4277426 posted 4:14 pm on Mar 6, 2011 (gmt 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

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4277426 posted 5:21 pm on Mar 6, 2011 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved