Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Help

rewrite

         

Mystique

8:19 pm on Feb 25, 2009 (gmt 0)

10+ Year Member



Hey Guys,

I need your help..

how to redirect folder & parameter to new location?

my current address is like this:

[search.example.com...]

i want to rewrite/redirect it to

[search.example.com...]

Thank You.

g1smd

11:44 pm on Feb 25, 2009 (gmt 0)

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



If this is going to be a redirect, then you'll need a RewriteRule with the canonical hostname specified in the target URL and with [R=301,L] at the end of the rule.

If it is for a rewrite then omit the domain name from the target and use just [L] on the end of the rule.

Whichever you use, you will also need a preceding RewriteCond that looks at QUERY_STRING values.

However, you need to make up your mind whether you want a rewrite or a redirect. They are different things, though their syntax is very similar.

Which URL do you want users to 'see' and 'use' on the web?

What is the 'real' filepath for the content as stored on the server?

Mystique

1:39 am on Feb 26, 2009 (gmt 0)

10+ Year Member



Hi g1smd,

Thanks for your response.

What i want to do is move my current folder and all its data named "find" to new location named "search". And visitors that go to old location (spider also counts) needs to be redirected to new location.

i have made a .htaccess to be placed in the "find" folder


# allow all except those indicated here
RewriteEngine on
Rewritebase /
RewriteCond %{QUERY_STRING} kw=(.*)
RewriteRule .* http://test.example.com/search?term=%1&subid=old [R=301,L]

can u check wheter my code is OK for this purpose?

Thanks

g1smd

2:00 am on Feb 26, 2009 (gmt 0)

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



*** move my current folder ***

Obviously my question was not very clear.

Do you want to change the URL that users on the web use to access the content? Or are you physically moving the content around inside the server?

However, if you are moving content around inside the server, you do NOT have to change the URLs that users use to access that content. That's what a rewrite is for.

It is not a good idea to change the URL that users use to access a resource; "Cool URIs don't change".

Which URL do you want users to 'see' and 'use' on the web?

What is the 'real' filepath for the content as stored on the server?

Mystique

2:16 am on Feb 26, 2009 (gmt 0)

10+ Year Member



i am physically moving the content around inside the server..

i have many indexed page at my old folder & i dont want lose that indexed pages because of moving my current folder.

my current index.php is in "find" folder rite now..

because i want to change to new turnkey script (that will be placed in "search" folder) so all URI will be changed.

P.S. Sorry english is not my primary language

jdMorgan

2:24 am on Feb 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



g1smd is trying to tell you that a URI and a filepath are not the same thing. They are only "associated."

You do not have to change the URI just because the file location changes. Simply map (rewrite) the "find" URI to the "search" filepath.

In /find/.htaccess :


RewriteEngine on
#
RewriteCond %{QUERY_STRING} kw=(.*)
RewriteRule .* /search?term=%1&subid=old [L]

Jim

[edited by: jdMorgan at 2:30 am (utc) on Feb. 26, 2009]

Mystique

2:30 am on Feb 26, 2009 (gmt 0)

10+ Year Member



how to rewrite the "find" URI to the "search" filepath?

but i want also to chang the paramater from (?kw=) to (?term=)

do my current code (above) won't work to accomplish this?

Mystique

10:23 am on Feb 26, 2009 (gmt 0)

10+ Year Member



Thanks jdMorgan for the code.

btw, just for my knowledge, how if i just want to rewrite only?

so in the address bar it looks

example.com/?kw=somekeyword

but it gather the page from

example.com/?term=somekeyword&subid=old

g1smd

11:04 pm on Feb 26, 2009 (gmt 0)

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



Something like:

RewriteCond %{QUERY_STRING} &?kw=([^&]+)&?
RewriteRule ^$ /?term=%1&subid=old [L]

But why have parameters in the URL if you are using a rewrite? You have parameters in the filepath, but you don't need to have them in the URL if you are using a rewrite. You could use

example.com/keyword
extensionless URLs instead.