1

I have a htaccess file that rewrites my url to a more friendly url

 #   '/'.$i.'/'.$company;
RewriteRule ^([0-9]+)/([a-zA-Z0-9\_\-]+)(/?)$ /offer.php?i=$1&company=$2 [NC,L]

this works fine unless in cases like below the page renders perfectly...

/14/barringtons-wedding-cars

/13/beef-and-pudding

/12/banks-printers

however when the name of the client contains say & symbol or any other symbol the url is writen like so......

/15/bella-%26-mr-tom

/17/bonton-hair-%26-beauty-salon

/37/fuego%27s-mexican-restaurant

and all of a sudden the page comes up as 404 not found. Is there anyway around this as I cant seem to fix it?

Daniel Robinson
  • 643
  • 1
  • 10
  • 25

2 Answers2

1

You don't need to change your .htaccess file, but you need to use slugs based on the $company variable when writing your url.

Instead of having this kind of url:

http://www.example.com/15/Fathers&Sons

You should write:

http://www.example.com/15/Fathers-Sons

This is the way stackoverflow and most websites works.

Have a look at the answer on this question, by using this code you could write '/'.$i.'/'.slugify($company); when writing your url in code.

Community
  • 1
  • 1
Florian Lemaitre
  • 5,905
  • 2
  • 21
  • 44
0

Try changing the Rule to the below, this should fix your issue.

RewriteRule ^([0-9]+)/([^/]*)?$ /offer.php?i=$1&company=$2 [L]