Dynamic URL redirect within particular subdomain using .htaccess

Share

Below are the lines you need to add in your .htaccess file to redirect /services/blahblah URLs to /offerings/blahblah for the sub domain mentioned in line 1 below (en.domainnamegoeshere.com). Dynamic URL redirect.

RewriteCond %{HTTP_HOST} ^en.domainnamegoeshere.com$
RewriteRule ^services/(.*)$ http://en.domainnamegoeshere.com/offerings/$1 [R=301,L]

Above lines will redirect all the URLs in pattern below.

Redirects
http://en.domainnamegoeshere.com/services/web
to
http://en.domainnamegoeshere.com/offerings/web

This will NOT redirect similar URLs in OTHER sub domains of your site except en.domainnamegoeshere.com.

Please login using google or facebook and create a forum topic to get your query answered in few hours here http://www.learn-drupal.in/forums/forum/drupal-forum-post-installation



Follow me

Sachin Wable

Sachin Wable is a technical blogger. He is blogging since 2010 & writes about Blogging, affiliate marketing & technical stuff. His blog learn-drupal.in receives 22,500 page views and visits from 1934 cities from 135 countries per year. (As per last years google analytics report.)
Follow me

Latest posts by Sachin Wable (see all)

affiliate_link

1,755 views

4 comments

  1. Vijay says:

    Nice post. This helped me a lot.

  2. shahmeer arshad says:

    how can i return a 410 header on a specific url using htaccess.

     

    • Sachin Wable says:

      Try this

      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^en.domainnamegoeshere.com/my-url$
      RewriteRule .* -[G,L]
      

      This should do 410 for your Url en.domainnamegoeshere.com/my-url

      • shahmeer arshad says:

        Thanks alot for your comments, will try it for sure.

        One more thing to ask my drupal redirects me to the actual post even if i write anything after the node number

        I am stuck at how to stop my website from redirecting on these(last two) urls.

        Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *