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?
Related
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.
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]
I have some pages on my website that use http and other pages that use https. Now I want to use mod_rewrite to append www to all URLs whether they use http or https.
I have my current code in .htaccess:
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index.php
RewriteCond $1 !^(index\.php|public|assets|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]
Please only focus on the first two lines as the rest are for other rewrite rules but I included it in case they were causing any errors for my first 2 lines.
Now this redirects all pages to http, but I want pages using https to be redirected to the right protocol. I tried the solution to a thread on StackOverflow (htaccess redirect for non-www both http and https) but it doesn't work for me.
The answer you linked should work perfectly. If it isn't working, the HTTPS variable probably isn't set. This usually happens because you're not doing the HTTPS on your apache server. Perhaps you have a proxy that does it, or a load balancer? In that case you need to make sure the HTTPS variable gets set. Something like this often does the trick (the example works for amazon elastic load balancers):
SetEnvIf X-Forwarded-Proto https HTTPS=1
I had issues when I tried to deploy my Rails site
when i start mongrel and start my app and rewrite and start with Apache
the application has ben displayed
but when i link to http://myapp.com/account/login
Not Found
The requested URL /account/login was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
when i try default myapp.com:12007/
it was normal, i can link
what is the problem ?
just for information
the problem is # .httaccess file
# folder public_html/
just need edited like this :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^myapp.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.myapp.com$
RewriteRule ^.*$ "http\:\/\/127\.0\.0\.1\:12007%{REQUEST_URI}" [P,QSA,L]
Try add NameVirtualServer *:12007 to the end of your apache2.conf file
I have configured Apache to look for the presence of a maintenance page and redirect to that page if it is present:
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.
RewriteRule ^.*$ /system/maintenance.html [L]
This is fairly standard practice for deploying Ruby on Rails apps.
What I'd like to do to create a URL exclusion list so the redirect doesn't occur for specific subdomains, e.g: https://user1.myapp.com/any_request_url or https://user2.myapp.com/any_request_url
Can this be achieved with extra RewriteCond statements?
This should do it:
RewriteCond %{HTTP_HOST} !^(user1|user2)\.myapp\.com$