I previously had below which worked ok,
RewriteEngine on
RewriteRule ^([0-9]+)/?$ /news/index.php?post=$1 [L,QSA]
But I don’t want it to open like this
https://example.com/news/index.php?post=123456
I want it to open only in such a way that it only allows numbers
https://example.com/news/123456
is the request that /news/index.php?post=123456 should not resolve Only /news/123456 should be accessible
Thanks
2
Answers
Hi to achieve this add the below lines and restart the services, where The provided rule ensures that the URL starts with "news/" and captures numeric values to append them to the URL as your expectation.
You need a combintation of both, an internal rewrite and an external redirection:
It is a good idea to start out using a
R=302
temporary redirection and to only change that to aR=301
permanent redirection once everything works as expected. That prevents caching issues with clients while you are still trying around.Above rules will work likewise in the central http server’s configuration and in a distributed configuration file (".htaccess"). If you have access to the central configuration then that should clearly be the preferred place to implement such rules.