I’d like to use htaccess to change my URL for my website
URL currently: example.com/index.php?p=my-topic-title
I want to be like : example.com/my-topic-title
my currrent htaccess file :
RewriteEngine on
RewriteRule ^p/([0-9أ-يa-zA-Z_.]+) index.php?p=$1 [NC,L]
the result for this code is:
example.com/p/my-topic-title
I want url to be (without (/p/) ) like :example.com/my-topic-title
2
Answers
Thanks, I solved it with:
I assuming you have already changed the URL in your application and you only need to redirect search engines/users in order to preserve SEO.
In which case, you can do something like the following before the above rewrite:
This assumes the page title is at least 3 characters. The
%1
backreference contains the captured subpattern in the preceding CondPattern. TheQSD
flag (Apache 2.4+) is necessary to remove the query string from the redirected URL.