IP Canonicalization , Rails 3 app - ruby-on-rails

I checked my site with online SEO checker and it suggested that I have to fix this error:
Your site's IP xxx.xxx.xx.xxx does not redirect to your site's domain name.
So as suggested I added some code to my htacces file located in public directory. Of course replacing x's with IP adress.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^XXX\.XXX\.XXX\.XXX
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
But then after app restart I checked again with SEO checker and again it shows the same error.
Here is my full htacces file:
PassengerAppRoot /home3/ecotec11/rails_apps/darbs/
<IfModule mod_passenger.c>
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
#Set this to whatever environment you'll be running in
RailsEnv development
RackBaseURI /
SetEnv GEM_HOME /home3/ecotec11/ruby/gems/gems
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.darbs.ecotechno.lv$ [NC]
RewriteRule ^(.*)$ http://www.darbs.ecotechno.lv/$1 [L,R=301]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
RewriteCond %{HTTP_HOST} ^173\254\28\107
RewriteRule (.*) http://www.darbs.ecotechno.lv/$1 [R=301,L]
Any suggestions?
Thanks

(1) Your actual IP 173.254.28.107 points to a hosting service. The hosting service cannot point to your site because it probably hosts thousands of other sites.
A solution might be to buy a dedicated IP from that hosting service. Depending on their policies, you might (or might not) have access to your own document root, or your public html directory might be your document root.
(2) If this were a dedicated server or at least dedicated IP, then the answer would be that you edited .htaccess located in a wrong place.
Place an .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} ^XXX\.XXX\.XXX\.XXX
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
in the default document root, the one where the index.html that says "There is no website configured at this address" is located. You can either look for a file named index.html or see what is the default document root in the Apache config file.

Related

.htaccess multiple domains in public_html with rails

I'm using a shared hosting account which allows me to host multiple domains, but they must all be within the same public_html folder. The "add-on" domains seem to work just fine, but I'm trying to get my primary domain to work properly. It is a Rails app, being hosted through Phusion Passenger.
My current mapping is as such:
primarydomain.com ---> ~/public_html/primarydomain/
addondomain1.com ---> ~/public_html/addondomain1/
addondomain2.com ---> ~/public_html/addondomain2/
My .htaccess is as follows:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?primarydomain.com$
RewriteCond %{REQUEST_URI} !^/primarydomain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /primarydomain/$1
RewriteCond %{HTTP_HOST} ^(www.)?primarydomain.com$
RewriteRule ^(/)?$ primarydomain/ [L]
which is based on recommendations from the hosting company. I don't worry with the add-on domains because the host automatically links those up properly through other configuration tools. I just need to make the primary one be hosted from a subdirectory.
The problem is that when I try to set up my rails app so that it maps like such
http://primarydomain.com --> ~/public_html/primarydomain/ --> ~/rails_apps/primary/public
It always fails giving me the following error in the log file:
Started GET "/primarydomain/" for 11.22.33.44 at 2014-01-11 21:58:29 -0700
ActionController::RoutingError (No route matches [GET] "/primarydomain"):
...
Any thoughts to how to resolve this?

URL be able to not type .php in url and direct to php file

i want to make this page http://www.jambagames.com/index.php to not show the ".php" at the end. Is it also possible to make php files my default on my godaddy server? Such as typing in http://www.jambagames.com/index and it'll go to that index.php page.
The process that you are asking here is to rewrite the URL's
To rewrite http://www.jambagames.com/index.php into http://www.jambagames.com/index you need to use these directives in your .htaccess file:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

How to rewrite urls

I have a site at xyz.com, for some reasons I want to redirect access to www.xyz.com to the url xyz.com. Even if they add 'www', I want to alter the address in their bar to xyz.com. Is there a way?
First enable mod_rewrite in your web server then use
.htaccess file in your directory with this content:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.xyz\.com$
RewriteRule ^(.*)$ "http\:\/\/xyz\.com\/$1" [R=301,L]

creating wildcard based subdomain [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Apache rewrite based on subdomain
I am stuck with one problem which not able to solve it. Plz help me to come out of this.
My requirement is:
I want to have each city name as sub domain in my site. Say www.mysite.com, which can have www.delhi.mysite.com, www.bangalore.mysite.com. The list might go endless. My problem is I don't want to create folders for each of the sub domains. I want to handle it in the URL as query string, say www.mysite.com?city=bangalore. This way I can redirect the request to a single file.
I have made the set up LAMP architecture.
In vhost file, it is
<VirtualHost 127.0.0.1:80>
ServerAdmin webmaster#localhost
ServerName www.mysite.com
DocumentRoot /var/www
</VirtualHost>
<VirtualHost 127.0.0.1:80>
ServerAdmin webmaster#localhost
ServerName *.mysite.com
DocumentRoot /var/www
</VirtualHost>
and Also updated .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mysite\.com [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.mysite\.com
RewriteRule ^(.*)$ http://www.mysite.com/index.html [R,L]
But still I am getting 404 error.
Is my approach correct?? Can it be achievable??
Please help me in doing this.
Try something along these lines:
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
RewriteRule ^/(.*)$ http://www.domain.com/%1/$1 [L,R]
plus a rule to not apply this to the www prefix.
And next time, please use the search function, this has been asked before.
Make sure you have enabled the rewrite module. Try putting the statements into your vhost config instead of .htaccess.

Remove WWW prefix from your website

How does Stack Overflow (and other web sites) remove the 'www' prefix when it's entered as part of a URL?
Is it a redirect, a rewrite or something else entirely?
Update: I'd specifically like to know in the context of IIS 6
On Apache, it looks like this (inside an .htaccess file):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
An easy way to do this is using the Apache "Redirect" directive:
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / http://example.com/
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
# remainder of server configuration goes here
</VirtualHost>
The Redirect directive automatically preserves anything following the / in the URL. I find this method easier to read and understand than the Rewrite method.
Firing up Fiddler, we can see that the server responses with a "301 Moved Permanently" status and refers it to http://stackoverflow.com .
Since StackOverflow is hosted on Windows 2k8 IIS7 they set up this redirect straight away in IIS7.
FYI:
a list of HTTP statuses
If you are a .NET developer you might know "Respose.Redirect" , this creates a 302 Object Moved status. Search engines like 301 status codes in this case better, because they know they should not come back to www.stackoverflow.com in the future.
You can do it several ways, using mod_rewrite and redirecting is my favorite. Something like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.cuenca.co$ [NC]
RewriteRule ^(.*)$ http://cuenca.co/$1 [R=301,L]
redirect. the sub-domain "www.stackoverflow.com" would simply redirect to "stackoverflow.com".
You need a default dns entry added pointing to your web server.
ping site.com and verify ip is pointing to webserver, if not you need to get the default DNS entry added.
for a basic setup:
You'll have to add host headers http://www.visualwin.com/host-header/
Create 1 site with a hostheader of www.site.com
In the Home Directory tab, set it to a permanent redirect to http://site.com
Create a 2nd site with a host header of site.com
If you want www.site.com/file.html to redirect to site.com/file.html you will need a more advanced setup with something like ISAPI_Rewrite or use custom 404 pages to do it.
You can do what mod_rewrite does for Apache, with a comparable URL rewriter for IIS. A good one is IIRF. The rule is:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [I]
RedirectRule ^(.*)$ http://example.com/$1 [R=301]
You can also wildcard the hostname like so:
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [I]
RedirectRule ^(.*)$ http://example.com/$1 [R=301]
IIRF is free to use.
For apache
<VirtualHost *:80>
ServerName yourdomain.tld
ServerAlias www.yourdomain.tld

Resources