Welcome to WebmasterWorld Guest from 54.158.228.55

Forum Moderators: brotherhood of lan & mack

Message Too Old, No Replies

RewriteRule Help

catch a name and rename

     
6:08 pm on Apr 9, 2009 (gmt 0)

5+ Year Member



Hello everyone,
I need to know if it is possible with the RewriteRule to catch a specific name in the url and rename with the new name.

For example:
To catch airagency and replaced it with airspace

www.domain.com/airagency/freedom.jsp or
www.domain.com/transport/airagency-plane.jsp

new redirection

www.domain.com/airspace/freedon.jsp and
www.domain.com/transport/airspace-plane.jsp

Thanks.

6:14 pm on Apr 9, 2009 (gmt 0)

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



Rewrites do not 'make' URLs.

If you need a new URL, then use that new URL in the links in your pages.

It is links that 'define' URLs.

.

If the internal filename on the server is not changing, theh use a rewrite as that will connect the URL request used out on the web, with the actual filename used inside the server, without revealing what that filename actually is.

.

If you have a new URL to replace an old URL, then use a redirect to force requests for the old URL to make a new request for the new URL. However, you still need to use the new URL in the links in your pages, and no longer link to the old URLs.

6:32 pm on Apr 9, 2009 (gmt 0)

5+ Year Member



Thank you so much for you're answer,

But the problems comes that my site has been online for a while and to avoid user that have a favorite of a page to have a 404 html error.

rules work well but I have many folder and file name with airagency that I would like to catch.

RewriteRule .*/airagency/(.*)$ /airspace/ [L,R=301]

Thanks.

6:59 pm on Apr 9, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



That was pretty close. I'd suggest:

RewriteRule ^(([^/]+/)*)airagency([^A-Za-z].*)?$ http://www.example.com/$1airspace$3 [R=301,L]

The "bounding" subpatterns are meant to prevent this redirect from being invoked if anything but a slash precedes "airagency" or if any letter(s) directly follow "airagency" -- for example, "blah/newairagency/blah" will not be redirected.

Jim

 

Featured Threads

Hot Threads This Week

Hot Threads This Month