Welcome to WebmasterWorld Guest from 54.227.5.198

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite confusion

     

breham

7:18 am on Mar 27, 2012 (gmt 0)

5+ Year Member



Hi,

I'm trying to redirect:

www.example.com/new_cars/cars.php?make=Vauxhall to

www.example.com/new_cars/Vauxhall.html

but can't seem to to do it - I have got it to redirect to

www.example.com/Vauxhall.html but can't seem to include the new_cars directory in the redirect

Any advice please?

[edited by: incrediBILL at 8:16 am (utc) on Mar 27, 2012]
[edit reason] exemplified URLs [/edit]

g1smd

7:30 am on Mar 27, 2012 (gmt 0)

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



Without seeing your code, can't offer much as to where you went wrong.

Do use a RewriteRule rather than Redirect or Redirectmatch.

Use example.com in this forum to suppress URL auto-linking.

lucy24

7:35 am on Mar 27, 2012 (gmt 0)

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



:: peering into crystal ball ::

He's applying mod_alias syntax to mod_rewrite, so he expects the whole preceding part of the URL to remain unchanged.

breham

8:01 am on Mar 27, 2012 (gmt 0)

5+ Year Member



Oops, my code didn't make it in!

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /new_cars/cars.php?make=$1 [L]


is what I'm using currently but that redirects to the root directory I want to keep it all in /new_cars/ directory.

phranque

1:22 pm on Mar 27, 2012 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



you're doing a rewrite there.
if you want a redirect you must specify the R flag, probably with a 301 value.
you can also get a redirect to work if you specify the hostname in the substitution string.
i would do both - to canonicalize the hostname and make it clear that it is a redirect.

breham

2:06 pm on Mar 27, 2012 (gmt 0)

5+ Year Member



you're doing a rewrite there.
if you want a redirect you must specify the R flag, probably with a 301 value.
you can also get a redirect to work if you specify the hostname in the substitution string.
i would do both - to canonicalize the hostname and make it clear that it is a redirect.


Thanks for that - are you able to give an example of what you mean please?

Basically what I want to achieve is

/new_cars/cars.php?make=brandname

to have a friendlier url of

/new_cars/brandname.html

phranque

3:04 pm on Mar 27, 2012 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I have got it to redirect to www.example.com/Vauxhall.html but can't seem to include the new_cars directory in the redirect


what mod_rewrite directives did you use for this?

g1smd

7:32 pm on Mar 27, 2012 (gmt 0)

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



to have a friendlier url of

/new_cars/brandname.html

mod_rewrite cannot "make" new URLs.

The very first step is that the links on your page should point to the friendly URL that you desire your users to "see" and "use".

URLs are defined in links.

mod_rewite kicks in only after that link is clicked.


You might want to replace
[^/]*
with
[^/]+
here. Your current rule allows
example.com/.html
to be a valid URL.

lucy24

10:09 pm on Mar 27, 2012 (gmt 0)

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



you're doing a rewrite there.
if you want a redirect you must specify the R flag, probably with a 301 value.

The code is right; it's the name that is wrong.
:: shuffling papers ::
###. I thought I'd written up some boilerplate on the redirect-to-rewrite two-step, but apparently not.
:: put on To Do list ::

Is this what you're trying to do overall?

IF user requests long ugly URL (via type-in or outdated bookmark) with query string, send them over to short pretty URL.

IF there is a request (either from human or from previous redirect) for short pretty URL, serve content from long ugly URL with query string.

If yes, then everyone is on the same page and we can continue :)

cwright2012

6:42 pm on Mar 30, 2012 (gmt 0)



Breham,

Have you found a solution yet? I am in the same situation. I emailed you my contact info for offline discussion.

Thanks,

g1smd

7:41 pm on Mar 30, 2012 (gmt 0)

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



As this is a question that comes up fairly regularly (like at least several times each month) there's a whole bunch of previous threads with example code that can be raided for ideas. Post your code here for discussion.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month