Rewriting rails url from port 3000? - ruby-on-rails

i have an applicaiton that runs at actionengineers.com:3000. How do i reqwite the application to a subdomain or directory (actionengineers.com/myapp) without disturbing the main site of course. i tried to use .htaccess file but i allways get eror 404. here is the code in the .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.deep.actionengeneers.com$
RewriteRule ^/?$ "http\:\/\/127\.0\.0\.1\:3000%{REQUEST_URI}" [P,QSA,L]

Try this rule:
RewriteCond %{HTTP_HOST} =www.deep.actionengeneers.com
RewriteRule ^ http://127.0.0.1:3000%{REQUEST_URI} [P,L]
Now all requests to www.deep.actionengeneers.com are getting passed through to 127.0.0.1:3000 via proxy.

Related

bluehost shared ssl redirect with htaccess

I am wanting to add a redirect to my bluehost shared ssl page:
https://secure.bluehost.com/~user/page_to_redirect
to here:
http://mydomain.com/folder/new_page
I need this setup, as I am using a website's API, which requires that the callback url is ssl. And i need this redirected to my ruby on rails app.
i have configured my .htacccess (root) like so:
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain.\.com$
RewriteRule ^/?$ "http\:\/\/mydomain\.com\/" [R=301,L]
Redirect /page_to_redirect http://mydomain.com/folder/new_page
the redirect works for the non ssl page:
mydomain.com/page_to_redirect
but not the ssl page:
https://secure.bluehost.com/~user/page_to_redirect
I just get a 404 error.
does anyone have any experience with this?
Bluehost support was not very helpful at all.
this is what worked:
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain.\.com$
RewriteRule ^/?$ "http\:\/\/mydomain\.com\/" [R=301,L]
Redirect 301 /~mydomain/page_to_redirect http://mydomain.com/folder/new_page
This is what worked:
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain.\.com$
RewriteRule ^/?$ "http\:\/\/mydomain\.com\/" [R=301,L]
Redirect 301 /~mydomain/page_to_redirect http://mydomain.com/folder/new_page

Removing .html and .php from links in IIS

As the title says, I would like to know how to remove ".html" and ".php" from links in a Windows server (IIS).
Most of the information I have found about this subject was only valid for Linux servers.
Only today I heard about the file web.config and got new material to study. Nevertheless, I am still struggling with it.
You can use the url rewrite module for IIS: http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module
Here is a good tutorial on the subject: http://www.surfingsuccess.com/asp/iis-url-rewrite.html
Read about friendly-url and .htaccess
See an example:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([a-z0-9-]+)/?$ index.php?pag=$1 [NC]
RewriteRule ^([a-z0-9-]+)/([0-9]+)/?$ index.php?pag=$1&id=$2 [NC]
</IfModule>
That way when you use:
localhost/contact
The server will do an internal redirect to:
localhost/index.php?pag=contact

redirect a url or domain with www

I have a simple question about url or domain redirect. I was looking through the previous questions on how to redirect a url or domain from http to http to force using ssl.
The weird part shows up when I try to redirect none www. to www. with the domain. I tried many ways, but none worked for me. does any one have any idea why is that?? and how to resolve this issue??
here is the code for I used at .htaccess:
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteRule ^/?$ "https\:\/\/www\.mydomain\.com\/main" [R=301,L]
another weird thing is that whenever I typed the domain on the browser without www. there is an error message, but when I insert the www. in front of the domain, it redirects with https and wwww of course.
any idea?
Thanks
You rules will run into a loop. Do this instead:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

.htaccess rewrite frustrations

I made my website in PHP originally and used parameters for page/product identification.
ex.) http://mysite.com/?pid=my_products&sid=golf_clubs&GTIN=111111111111
I've now moved over to using RoR and I'd like to set up redirects to clean up the urls
http://mysite.com/my_products/golf_clubs/111111111111
I've looked at tutorials and arrived at this:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ ?pid=$1&sid=$2&GTIN=$3 [NC]
I've tested a url and it doesn't redirect at all. I've tried putting this in the .htaccess file to debug and chmodded the log folder to 775 but I get a 500 error:
RewriteLog "/home/myaccount/rails_apps/myapp/log/rewrite.log"
RewriteLogLevel 3
As far as rewrite statements in .htaccess goes, this is what I have:
RewriteEngine On
RewriteLog "/home/myaccount/rails_apps/myapp/log/rewrite.log"
RewriteLogLevel 3
RewriteBase /
RewriteCond %{REQUEST_URI} ^/downloads.*
RewriteRule .* - [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ pid=$1&sid=$2&GTIN=$3 [NC]
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
* I am on a shared hosting plan with Bluehost (good gawd I wish they'd update to Rails 3 soon)
If I understand you correctly, you have your rule backwards. You want to catch your old URLs and rewrite them to the new format, correct? In that case, you want this:
RewriteRule ^\?pid=(\w+)\&sid=(\w+)\&GTIN=(\w+) /$1/$2/$3 [NC,R=301,L]
Adding a 301 status will tell the user agent (including well-behaved search bots) that your canonical URLs have permanently changed.

How do I edit .htaccess to allow both rails and wordpress requests?

I want to run an instance of wordpress within my rails app. I currently have wordpress files housed in public/wordpress, but I need to configure my .htaccess file to allow both types of requests. How do I do that? currently, .htaccess is:
General Apache options
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)/!$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
ErrorDocument 500 "Application error Application failed to start properly"
You should start by adding this to the .htaccess in your public folder:
RewriteCond %{REQUEST_URI} ^/wordpress.*
RewriteRule .* - [L]
However, this is not the whole story. You also need to edit /etc/apache2/sites-available/
with this addition (to tell Rails not to process anything in /blog as part of the app):
<Location /wordpress>
PassengerEnabled off
Also in /etc/apache2/apache2.conf you may need to tell Apache to make any directory index (e.g. wordpress/) execute an index.php file if there is one:
DirectoryIndex index.php

Resources