Jump to content

Cant redirect my URL with htaccess


RahulVicky001

Recommended Posts

I am using WAMP and my url is localhost/hotel/hotels.php?id=21
Using rewrite rule as follow,

Options +FollowSymLinks
RewriteEngine on
RewriteRule hotels/id/(.*)/ hotels.php?id=$1
RewriteRule hotels/id/(.*) hotels.php?id=$1

But nothing happens..

My mod_rewrite is on and also changes done in httpd.conf file.

Please give me a suggesstion to handle the issue?     

Link to comment
https://forums.phpfreaks.com/topic/286535-cant-redirect-my-url-with-htaccess/
Share on other sites

This is not how mod_rewrite works. It does not automatically change the urls for you. You need to change your existing urls to the new url format that matches the rewriteRule you setup in the .htaccess. eg change your links to

echo '<a href="/hotels/id/'.$hotel_id.'>View Hotel</a>';

When you click the link you'll go to locahost/hotels/id/21. Here mod_rewrite will match that url with the rewriterule in the htaccess. It'll now pass the number 21 to hotels.php?id=21.

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.