.htaccess SEO Dynamic Urls Not Working

- 1 answer

I have a page with a link with a query string that loads another page with the result of the query.

a target="_blank" rel="nofollow noreferrer" href="news-detail.php?nrf=<?php echo $ntitle; ?>"><?php echo "<img src=newsimgs/thumbs/".$nphoto1.">" ?></a>

Now when the new-detail page loads, i get the url as

But i want it to load as

I have looked online for tutorials on mod_rewrite and tried different samples but for reasons beyond my understanding, i cant get it to work. one of the sample code i have tried is

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news-detail/([A-Za-z0-9-]+) news-detail.php?nrf=$1 [NC]


This should work when i click the link that loads the details page but it dose not. The page still loads with the link as

When i type directly in the browser,, the page actually loads but the links to the css, js, images, etc, are all broken. I have tried so many ways to resolve this but cant seem to find a solution. Is it the link with the query string that is the problem or is it something else, i just don't know. Any help would be much appreciated. Thanks in advance.



Using mod_rewrite doesn't replace the links inside your documents. You have to do this inside your own code:

<a target="_blank" rel="nofollow noreferrer" href="news-detail/<?php echo $ntitle; ?>"><?php echo "<img src=newsimgs/thumbs/".$nphoto1.">" ?></a>

After that, you must also update the paths to your external resources, as the called page is now in a sub-directory. So you could append ../ to all included client side resouces inside the detail page.

To prevent this, the better way would be to use absolute paths or add the <base /> to the page's header.