How to make %{HTTP_HOST} always return non-www

I have this redirect code and I want it to always return %{HTTP_HOST} as non-www no matter what sub-domain was used.

RewriteEngine On
RewriteRule ^.*${HTTP_HOST} [L,R=301]

So, , , will always be redirected to

Thanks for your time.


I would use Google, and click the first link.

Then you can just change the RewriteCond to match anything, rather than specifically not-www

You could try something like this:

# we are now working on HTTP_REFERER,
# change to appropriate variable according to your needs
#   check if we got at least 2 dots in the URL
RewriteCond %{HTTP_REFERER} \.([^\.]+)\.([A-Z]{2,3})$ [NC]
#   if the condition was met, redirect using only last 2 parts of URL
RewriteRule ^ [R,L]

Let me know if this was helpful.

Have your Rewrite rule like this:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(?:[^.]+\.)(.+)$ [NC]
RewriteRule ^{REQUEST_URI} [L,R]

Need Your Help

Single page application using grunt and tomcat

angularjs tomcat gruntjs

We are building single page application, using AngularJS and Spring Rest services along with spring boot. For front end build we are using grunt and for server site build maven. But we are not sure...

How to use AutoLayout with UIScrollView

ios objective-c xcode uiscrollview autolayout

I have a problem with the auto layout on an UIScrollView.