URL rewrite [Beginner]

Hi folks,

i want when the client navigates to following url

http://www.example.com/view-property.php?pid=116

he should be seeing the below url in address bar

  http://www.example.com/property/116

i tried the following

RewriteEngine On
RewriteBase /
RewriteRule ^property/([0-9]+)/?$ view\-property\.php?pid=$1 [NC,L]

but it does not work :frowning:

The first thing to be aware of is that rewrite rules donā€™t ā€œchangeā€ URLs per se. They enable the alternate, clean version of the URL. If you type the ugly URL into the address bar, itā€™ll still work. Rewrites make it so that you can also type the pretty URL into the address bar, and itā€™ll work too.

With that cleared up, probably all you need to do is remove the backslashes.

RewriteEngine On
RewriteRule ^property/([0-9]+)/?$ view-property.php?pid=$1 [L]

I also removed the RewriteBase and the NC. Neither of them were causing your problem, but you donā€™t need them.

afridy,

Ditto the optional trailing / as it will cause problems with your relative links.

Regards,

DK

Thanks so much jeff_matt,
yes not it works, but one problem. when i execute http://www.example.com/property/116, the page that appear seems jammed and no any css style is loaded. But the original page http://www.example.com/view-property.php?pid=116 is clean and neat. what could be the problem?

Also, in the tutorial i was reading, it said to escape any dashes. thatā€™s y i had escaped the dashes.

hmm, did not get you buddy, which slash u mean to remove?

afridy,

RewriteRule ^property/([0-9]+)/?$ view-property.php?pid=$1 [L] ^^

Regards,

DK

done sir

RewriteEngine On
RewriteRule ^property/([0-9]+)?$ view-property.php?pid=$1 [L]

afridy,

Aw, dump that ? in the regex, too! Thatā€™s what made the / optional.

Regards,

DK

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.