how to resolve htaccess redirect issue with website

Viewed 50

My website is not stripping the text in * condition.

Website URL is like http://www. domain.com/search/adasd I want to redirect it to https://www. domain.com/noindex-page

Using below redirect rule

RewriteRule ^search/\*$ https://www. domain.com/noindex-page? [L,R=301]

but it is redirecting to https://www. domain.com/noindex-pageadasd and giving 404 not found.

Please suggest how to strip adasd from this.

Using * is necessary as there are number of URLs with this prefix.

1 Answers

Based on your shown samples could you please try following. I believe problem in your regex \* is you have escaped * which means it is NO longer matching everything after search keyword and is treated as a literal as * hence it may not be working. Since you are looking for anything after search keyword then we could simply check if uri starts from search here.

RewriteEngine ON
RewriteRule ^search https://www.yourdomain.com/noindex-page? [L,R=301,NC]
Related