Himanshoo Posted October 15, 2022 Share Posted October 15, 2022 i am trying to implement seo friendly url to my website. for page where no parameter passed, the url becomes fine i.e., without php extension but where i am sending variable parameter, it does not change. Please check below 2 type of code i try to implement. First code in htaccess: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ makeurl.php?url=$1 [QSA,L] makeurl.php code: <?php //echo "<pre>"; //print_r($_SERVER); $hid = $_GET['hid']; $request = $_SERVER['REQUEST_URI']; //echo "<br>"; $router = str_replace('/wavehotels', '', $request); if($router == '/'){ include('index.php'); }elseif($router == '/hotels'){ include('hotels.php'); }elseif($router == 'hotel-detail' || preg_match("/hotel-detail\/[0-9]/i", $router)){ include('hotel-detail.php'); }elseif($router == '/destinations'){ include('destinations.php'); }elseif($router == '/about-us'){ include('about-us.php'); }elseif($router == '/blogs'){ include('blogs.php'); }elseif($router == '/contact-us'){ include('contact-us.php'); }else{ include('404.php'); } ?> i m getting result for nornal pages: www.abc.com/about.php is result in www.abc.com/about but the issue is in where parameter passed like www.abc.com/product.php?id=2 no change in this url, i want the result like www.abc.com/product/2 any input will be appreciated. Thanks Himanshoo Quote Link to comment https://forums.phpfreaks.com/topic/315424-not-getting-result-for-desited-url/ Share on other sites More sharing options...
Himanshoo Posted October 15, 2022 Author Share Posted October 15, 2022 i re write my code which works fine when writing url manually not from anchor tag Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^detail/([0-9]+)$ hoteldetail?hid=$1 [QSA,L] when i type manually it displays data fine like www.abc.com/detail/4 but when i come from anchor tag from main page it display url like www.abc.com/hoteldetail?hid=2 url not changed but data displays perfect. Quote Link to comment https://forums.phpfreaks.com/topic/315424-not-getting-result-for-desited-url/#findComment-1601661 Share on other sites More sharing options...
requinix Posted October 15, 2022 Share Posted October 15, 2022 URL rewriting does not affect what happens in <a> links. You have to write those with the URLs you want. <a href="/detail/4"> Quote Link to comment https://forums.phpfreaks.com/topic/315424-not-getting-result-for-desited-url/#findComment-1601678 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.