: How to regex a url to redirect user Using the regex and the .htaccess file, I want to redirect users to a certain URL. I want to redirect: http://www.example.com/* but not http://www.example.com/CDadmin/*
Using the regex and the .htaccess file, I want to redirect users to a certain URL.
I want to redirect:
www.example.com/* but not www.example.com/CDadmin/*
I have tried the following:
www.example.com/CDadmin/[*-^$CDadmin/*]
But does not work when I test with regex101.
More posts by @Dunderdale272
1 Comments
Sorted by latest first Latest Oldest Best
Since you've not clarified the specifics of your question, I'll make some assumptions:
You wish to redirect to a different domain. eg. example.net
example.net points to a different server.
/CDadmin is a physical directory on the filesystem.
At the top of the .htaccess file in the document root of example.com, place the following:
RewriteEngine On
RewriteRule (.*) example.net/ [R=302,L]
The only regex here is (.*) - which will basically redirect everything. (Read on...)
This is a temporary (302) redirect. Change to a 301 if you want to make it permanent.
Then, in the .htaccess file in the /CDadmin subdirectory, simply enable the rewrite engine:
RewriteEngine On
This will effectively override the mod_rewrite directives in the parent .htaccess file, so nothing will be redirected when accessing /CDadmin/<something>.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.