Forum Moderators: phranque

Message Too Old, No Replies

Rewrite/Hiding variable

         

Mystique

1:34 pm on Aug 2, 2009 (gmt 0)

10+ Year Member



Hi, Guys..

I Really need your help about mod rewrite. this part is always be my weakness. :(

Basiacally i want to hide 'qq' varible name:

http://www.example.com/?qq=keyword

to just

http://www.example.com/keyword

so it still pass keyword to 'qq' variable

I have already make a htaccess rule but it seems not working


#Options +FollowSymLinks
RewriteEngine on
#RewriteBase /
RewriteRule ^(.*)$ ?qq=$1 [L]

and i dont know how to send all value after '/' to qq variable except filename.. so filename request will be processed normally

Anyone can Help with this?

jdMorgan

2:41 pm on Aug 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make the pattern so that it matches unless there is a "." in the final path-part -- after any "directory levels" denoted by slashes:

Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^(([^/]+/)*[^.]+)$ ?qq=$1 [L]

Note that this doesn't change your URLs. You must change the links on your pages to use the "/keyword" format. After you've done this, your rewriterule will match requests for "/keyword" requests, and change them to "/qq=keyword" form to "send them to your script."

Note that all images and included objects on your pages will need to use server-relative or canonical URLs. For example, refer to images as <img src="/images/logo.gif"> or <img src="http://www.example.com/images/logo.gif"> instead of <img src="images/logo.gif">

Once you get that working, you may wish to add a second rule to *redirect* direct client requests for the old dynamic URLs to the new static/SEO-friendly URLs.

Jim

Mystique

3:43 pm on Aug 2, 2009 (gmt 0)

10+ Year Member



Hey, Million Thanks Jim..

it works.. but i'm still dont understand with this part:

Note that all images and included objects on your pages will need to use server-relative or canonical URLs. For example, refer to images as <img src="/images/logo.gif"> or <img src="http://www.example.com/images/logo.gif"> instead of <img src="images/logo.gif">

why i need to change it to use '/' infront all of them?.. but it seems work fine without that slash..

and is it (/) also must be used in php script at 'include' part?

BTW, what code to use if i want to redirect old url to the new one?

example.com/search/keyword (old)

to this new one

example.com/keyword

currently i'm uplace this htaccess to /search folder


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://example.com/$1 [R]

is is OK/ correct?

Thnaks

jdMorgan

5:08 pm on Aug 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> and is it (/) also must be used in php script at 'include' part?

No, because "include" is a *file* include, and does not make use of HTTP transfers. Therefore, .htaccess has no effect on "include."

The code you posted in your last post has nothing to do with your original question, so I can't say if it is "OK" or not. It is a 302 redirect, and is missing the [L] flag. That is all I can say.

Jim