Jump to content

Friendly URL


sotusotusotu

Recommended Posts

Hi,

 

Not really sure if this is a PHP or .htaccess problem, or both.

 

I am trying to implement a search which has a friendly URL. So for example 'www.site.com/search/keywords'.  In order for this to work I use .htaccess to redirect the URL. Here's my .htaccess code:

 

RewriteRule ^search/([^/]+) rewrite_files/search.php?result=$1 [NC,Last]

 

In gereral everything is working fine, for the exception of illegal characters such as '&', e.g 'www.site.com/search/me&you', so I use Javascript ('escape()') to URL encode.  In this case the URL would be www.site.com/search/me%26you'. If I wanted to print out the 'result' onto the page I only get the characters before the '&', so in this case I only get 'me'.  PHP's 'urldecode()' does not seem to work when .htaccess is used but I don't know why.  If I remove the .htaccess and use 'rewrite_files/search.php?result=me%26you' I am able to decode the URL and print out my result onto the page.

 

Is there another way / different way of getting my nice encoded URL?

 

Cheers guys

Link to comment
https://forums.phpfreaks.com/topic/196818-friendly-url/
Share on other sites

www.site.com/search/me%26you is hardly a friendly url, nor is www.site.com/search/me&you

 

you pages should be named using hyphens for ultimate seo-friendly urls: www.site.com/search/me-and-you

 

store them in the db as a slug, and encoding will not be an issue anymore as you won't have to do it.

Link to comment
https://forums.phpfreaks.com/topic/196818-friendly-url/#findComment-1033213
Share on other sites

I'm not worried about SEO in this case. I just want a tidy URL like WikiPedia.

 

Thee problem with replacing the & with a hyphen is that my search page is a db driven search query, therefore 'me-and-you' would return no results as the thing I'm looking, in this case, is called 'me&you'.

 

Make sense?

Link to comment
https://forums.phpfreaks.com/topic/196818-friendly-url/#findComment-1033219
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.