using rewriteRule on bitnami LAMP instance - bitnami

I am on a bitnami LAMP instance in AWS. I am trying to force users who try to get to www.rdsubstantiat.com to instead go to www.rdsubstantiat.com/sub_crud. To do this I put the following line into my bitnami.conf file in the VirtualHost default:443 section. Why won't this work?
RewriteRule "www.rdsubstantiat.com" "https://www.rdsubstantiat.com/sub_crud" [R]

Bitnami Engineer here,
This rule is wrong, you don't need to specify your domain. You can use this one
RewriteRule "^/$" "/sub_crud/" [R,L]
https://httpd.apache.org/docs/2.4/rewrite/flags.html
I hope this helps

Related

Remove “www” from website link

So, I have a rails project deployed using apache server. Unfortunately, the domain name is not registered with www. So if I do https://mydoin.com it works but https://www.mydoin.com doesn't. Now what I need is that, if someone uses this URL with www https://www.mydoin.com then I want to remove www from the URL. How can I do this? I am using Ubuntu 16.04 and apache 2.4.
First, you need to register the www.mydoin.com DNS, without this, your server will not be reached by your user. After this, you can configure a redirect in your server or rewrite your requisition, for this, follow this link: How to always remove WWW from a url with mod_rewrite?
This code will auto strip the www. for you even if its a subdomain.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
If you want to fix you DNS issue just add a 'A' record with www.yourwebsite.com

Rails - .htaccess not forcing users to use https

I want user to only be able to access the https version of the site. I figured out that a way to do this is with a .htaccess file. I've have added the SSL cert and thats all working fine.
I made the .htaccess file and added the following code in it (replacing 'example' with the domain name)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
I deployed it and visited http://example.com/ and it loaded just fine as http.
I dont know if because its a rails app that I might need to put the .htaccess file in the public folder, or if there is more I need to do. But from what I read this should work.
I'm using google cloud platform to host my site, and I cant find the VM server type so maybe its not the right server type to run .htaccess files on?
I'm hoping someone here knows how to get this working.
With .htaccess try the following:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
However, with Rails you can use the following in your environment config:
config.force_ssl = true

How to deploy rails 3 app using parallels Plesk?

How to deploy my Rails 3 app on shared hosting ?
When I buy hosting, they clearly mention Ruby on Rails support.
My hosting is Linux. The hosting service provider's technical member also don't know how to use Rails app. He is just saying that you can use Rails apps with FastCGI.
The hosting provider also does not allow to SSH access!
Thank you in advance.
There appears to be some threads out there on this:
forum.parallels.com/
kb.parallels.com/en/5489
Resolution
As of version 8.1, Plesk Control Panel supports Ruby on Rails. There is not an option in the Plesk Control Panel that should be checked to enable Ruby on Rails support; you only need to install the ruby packages.
To install an application written in Ruby, take the following steps:
Go to Domains > your-domain.com > Setup.
Select the CGI and FastCGI check-boxes and click OK.
Connect to your FTP account, change to the /htdocs directory, and create a subdirectory where the application files will reside. Let's call this directory your_application, for illustration purposes.
Upload the application files to the htdocs/your_application directory.
Create a file with the name .htaccess in this directory, open it with a text editor of your choice, and add the following lines into the file:
RewriteEngine On
RewriteRule ^$ /public/index.html [L]
RewriteCond %{REQUEST_URI} !^/your_application/public
RewriteRule ^(.*)$ /public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/dispatch.fcgi/$1 [QSA,L]
Save the file.
Remove the your_application/public/.htaccess file.
Open the your_application/public/dispatch.fcgi file with a text editor and put the following lines there: #!/usr/bin/ruby
Save the file.
The web application will now be accessible at the following URL: http://your-domain.com/your_application

Canonicalization in Rails - routing or .htaccess?

I have a site that is about to launch and a request for URL Canonicalization has been made. I want to know what is the best way to have all requests for http://www.example.com to permanently redirect (301) to http://example.com within my RoR app? Or, asked another way, how can I strip the "www." from all generated urls, paths, requests?
FYI, this is a Rails 3 app.
This is done using rewrite rules in the webserver.
For nginx: http://techtitbits.com/2010/07/wwwno-www-rewrite-rules-for-nginx/
For Apache: http://www.boutell.com/newfaq/creating/withoutwww.html
Also note that you should add two A records into your DNS zone file, like so
# IN A 10.0.0.1
www IN A 10.0.0.1
with 10.0.0.1 replaced with your IP address.
For Apache, You can add the code below to your /public/.htaccess file in your ROR app.
I use this for most of my apps, because I don't like the 'www'
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,L]
Hope this helps

what's the best way to force a domain with a rails app? ex: example.com instead of www.example.com

My rails app seems to break when it answers on www.example.com, it previously was working fine with just example.com...however I've moved servers recently and would like to know the best way to redirect all www.example.com requests to go to http://example.com/.../
thanks.
This should do the trick, assuming that you have mod_rewrite enabled
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.com
RewriteRule ^(.*)$ http://example.com$1 [R=301,L]
It depends on your server setup and there are different ways. You can just cname www in DNS to the root domain, for one way. If you are running Rails behind Apache then you can do it in Apache with mod_rewrite. If you are taking network requests straight into Rails with eg, mongrel (or webbrick) then you may have to configure those servers, or might have to use Rails routes ?
Hope that helps,
adricnet
According to the Apache's name-based virtual host documentation the first virtual host is the default host. I use this to make the first entry a catch-all that redirects every "undefined" request to the main site:
# Default catch-all
<VirtualHost *:80>
# Note the lack of a ServerName
RewriteRule ^(.*)$ http://www.example.com$1 [redirect=permanent]
</VirtualHost>
# Site 1 - www.example.com
<VirtualHost *:80>
ServerName www.example.com
[ the rest of the site config ]
</VirtualHost>
For extra credit you can set up a wildcard DNS entry so that every undefined host (e.g. asdfasdfasdfas.example.com) gets redirected to www.example.com.
You might not want to hear it but I suggest fixing what breaks instead. You've hard coded your domain somewhere in your app, probably in your routing but it is not possible to tell without the specifics of the error(s), and you need to remove that so you, or some other maintainer, won't have to deal with it again in the future.

Resources