Url rewriting remove the file name "news.php? Url =" from url

The URL is dynamic. I have the URL xyz.com/news.php?url=Facebook-launch-new-messenger-news-16680.php

but here I want to remove " news.php? url = " from my above url.

I go to this page from my index page by clicking on the link

<a href="news.php?url=<?= $row['url'];?>"><?= $row['title'];?></a>

I use this rewrite code in .htaccess

RewriteEngine On

RewriteRule ^([a-zA-Z0-9-/]+).php$ news.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+).php/$ news.php?url=$1

help me.

+4
source share
1 answer

Try to introduce a code rule, it will work for non-existing php files.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+).php/?$ news.php?url=$1 [L]
+1
source

Source: https://habr.com/ru/post/1669651/


All Articles