Forum Moderators: phranque

Message Too Old, No Replies

Fetch address - write it to .htaccess for NOVICE!

write to .htaccess

         

le007

7:35 pm on Sep 15, 2007 (gmt 0)

10+ Year Member



Hey all,

say my site after going through a search comes up with this address:
[mysite.com...]

how could I get it sent through .htaccess

like with this:

if I put this in .htaccess instead of [mysite.com...]

RewriteEngine On
RewriteRule ^email$ index.php?locate=email

the person would only need to type:
[mysite.com...]

Somebody please tell me how to do the same for this:
[mysite.com...]

so they'd only have to type in:
[mysite.com...]

How can the PHP do this on the fly? I really dunno how to do it... fetch it from the db and write it etc - complete novice... I have a mysql db set up with the data in it already.

Thanks!

PS I've tried this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^/]+)(/([^/]+))?$ index.php?locate=results&city=$1&state=$3&minp0&max=9&othercritera=%&moregoeshere

I tried the above and when I typed in
mywebsite.com/state

it worked but when I typed in
mywebsite.com/state/city it didnt

ALSO how can I have to parsed through the php so
mywebsite.com/state/city appears in the address rather than
index.php?locate=results&city=$1&state=$3&minp0&max=9&othercritera=%&moregoeshere

Thank you

jdMorgan

11:30 pm on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to change the links on your pages to the 'friendly' format, either by saving and retrieving those friendly URLs in the db records, or by using something like preg_replace in the PHP code that produces the link. The on-page links absolutely define the URL, and mod_rewrite cannot 'change' it.

What mod_rewrite can do, is to 'map' one of those friendly URLs, when it is requested from your server, to the correct script/query string call needed to produce the page for that friendly URL.

More info here [webmasterworld.com], including the process to 'clean-up' the unfriendly' URLs in your last question.

Jim

le007

4:42 pm on Sep 16, 2007 (gmt 0)

10+ Year Member



Hey jd, thanks for getting back to me.

I get what you mean that mod_rewrite only works if someone types in the specific url - it redirects it so to speak.

The preg_replace though, I need to get this in the php so as the new url will be in the address.