How to make a .htaccess wildcard redirect from everything with a URL prefix to everything without?

All my webpages had a URL prefix he/.
I have recently removed this URL prefix from all webpages and now I need to create a wildcard redirect to redirect from any to any

How to do it in .htacess?

Thank you.

What have you tried so far? There are loads of examples around on this forums to get you started.

Before posting this I didn’t try anything because I don’t know Apache Perl Compatible Regular Expressions and didn’t find a session to start with, for this small task, and hoped to learn some by an easy detailed example.

Anyway, the Namecheap support staff helped me by inclining this pattern (in the website’s .htaccess):

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^he\/?(.*)$ "https\:\/\/example\.com\/$1" [R=301,L]

Yup, that’ll do it. It can be optimized a bit, but it’s good enough.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.