Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect all urls with matching keyword to one single url?

I need to redirect all urls with matching keyword, regardless of position in link, to one single url on same site.

Example:

Links with word "book"

www.domain.com/booklovers.php

www.domain.com/booksforall.php

www.domain.com/bestbooksonamazon.php

www.domain.com/somethingaboutbooks.php

to be redirected to one single url on same domain,

www.domain.com/books.php

For now, I am focusing on

RewriteEngine On
RewriteRule ^.*book.*$ /books.php [L,QSA]

but it is not working. I tested same expression

^.*book.*$

in tester on http://tools.netshiftmedia.com/regexlibrary/ and it works, but in .htaccess it does not work. I am reading various answers here and learned a lot on other examples, but I can not find nothing for my case.

like image 395
user1457666 Avatar asked Dec 05 '25 10:12

user1457666


1 Answers

Try something like this after making sure AllowOverride is set to All in your virtualhost config and that mod_rewrite is enabled:

RewriteEngine on
RewriteBase /
RewriteRule book books.php [L,QSA]
like image 124
Ansari Avatar answered Dec 08 '25 04:12

Ansari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!