Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


htaccess redirect

Posted on 2012-09-06
Medium Priority
Last Modified: 2012-09-07
Hello all,

Is it possible to create a redirect rule when an url does not contain anything after the domain extension? Because I have a local, production and live version the domain extension should be treated as variable.

mydomain.nl -- redirect to --> mydomain.nl/nl
mydomain.nl/ -- redirect to --> mydomain.nl/nl
mydomain.local -- redirect to --> mydomain.local/nl
mydomail.nl/fr -- no redirect
mydomail.local/fr/whatever/comes/next -- no redirect

Can this be done?


Question by:wal_toor

Expert Comment

by:Derek Jensen
ID: 38372554
You should be able to accomplish this using a regexp similar to the following:

Open in new window

This will match both domains you have listed above; however, I'm sure you'll have to modify it to your needs.
I'm not sure what the exact syntax of the rule should look like, but I do know that .htaccess supports regexes.
LVL 26

Accepted Solution

arober11 earned 2000 total points
ID: 38375863

RewriteEngine On

RewriteCond  %{HTTP_HOST} mydomain.nl    [OR]
RewriteCond  %{HTTP_HOST} mydomain.local
RewriteRule  ^/?$    /nl   [L,R=301]

Open in new window


Author Closing Comment

ID: 38375979
Spot on!

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
What You Need to Know when Searching for a Webhost Provider
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question