Forum Moderators: phranque

Message Too Old, No Replies

URL getting redirected to query part

URL is getting redirected to the query part and not showing alias part

         

kb0000

7:32 pm on Feb 18, 2012 (gmt 0)

10+ Year Member



I am using .htaccess for URL rewriting. I have used code like:
RewriteRule ^([a-zA-Z0-9-_]+)$ index.php?page=d/ctg/item&itmctgals=$1 [QSA]

and URL is smstongue.com/friendship-sms (the alias URL) but it is showing URL with query part in URL i.e. [smstongue.com...]

But I want to show URL like smstongue.com/friendship-sms in browser URL bar.
How to do this.

g1smd

7:37 pm on Feb 18, 2012 (gmt 0)

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



Add the [L] flag to your rule.

Link to the friendly URL from the pages of your site.

Make sure the internal rewrite appears AFTER any and all rules that perform an external redirect function.

kb0000

7:46 pm on Feb 18, 2012 (gmt 0)

10+ Year Member



I have changed the rule to:
RewriteRule ^([a-zA-Z0-9-_]+)$ index.php?page=d/ctg/item&itmctgals=$1 [L,QSA]

But still it is showing query URL and not friendly URL.

g1smd

8:08 pm on Feb 18, 2012 (gmt 0)

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



Do the links on your pages point to the new URL you want users to see and use?

URLs are defined in links. It is too late to "change" a URL after the link is clicked.

A RewriteRule doesn't make a URL, it reacts to the URL request after the on-page link is clicked.

lucy24

1:25 am on Feb 19, 2012 (gmt 0)

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



It is showing the query URL because you haven't told it not to.

Your examples give one half of the change: when you get a request for a pretty URL, serve content from an unpretty location. You also need the other half. That's where you redirect the original un-pretty URL to the new pretty form-- if and only if the user requested the un-pretty URL by clicking an outdated link on someone else's site, or using an outdated bookmark.

kb0000

3:43 am on Feb 19, 2012 (gmt 0)

10+ Year Member



@g1smd
Yes, links on my page point to new URL which I want users should see. The URL is: smstongue.com/friendship-sms

@lucy24 But my first half should also work.

lucy24

6:45 am on Feb 19, 2012 (gmt 0)

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



OK, let's walk through this. Open up Firefox with Live Headers-- or equivalent in another browser. Any extension that lets you see exactly what happens behind the scenes.

Manually enter a pretty URL into your browser's address bar. What happens?

Manually enter a non-pretty URL (the kind with query) into your browser's address bar. What happens?

You don't have to read fast. You can save the whole Live Headers output as text and pore over every step.

For now, just use URLs that are "supposed" to work-- ones that should lead to a real page. Later on you will have to make sure that something appropriate happens if you enter a garbage URL. (A 404 error will be fine. But you need to make sure you don't end up with a 500 or an infinite redirect.)