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

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

Related

How to remove index.php from url in Laravel 5.1?

i am trying to run my project on client's server with the following url:
http://quotes.simplybridal.com/simply-bridal-backend/login // It Gives 404 Not Found Error
But it works for:
http://quotes.simplybridal.com/simply-bridal-backend/public/index.php/login // It works
now, my question is how can we remove this index.php from the url.
here is my .htaccess file content, which i placed outside /public folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /simply-bridal-backend/
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Any help would be really appreciated.
Looks like an Apache issue.
Can you post your Virtual Host content (or .htaccess)?
Check your document root variable (that should be something like /foo/bar/public (with no trailing slash)
--
Put this default .htaccess and make sure the route exists and it is reachable.
Options -MultiViews
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Zend Framework 2 without Vhost configuration

I had finished my first web application using Zend Framework 2 and I'm about to put it online.
But may web host doesn't allow me to change my vhost configuration!
The .htaccess file is allowed.
So my question is: How to set up my ZF2 app with only .htaccess files?
Assuming you have a standard ZF2 application based of the skeleton, then try creating a .htaccess file in the root with this in it:
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
I haven't tested this, but in theory, this should effectively move the document root to the public directory while keeping it out of the url.

.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.

Symfony 1.4 Error 400 on the home page in prod env (not in dev env)

I have made an tested an application on my computer and all is working fine (I used only the dev environment via the frontend_dev.php page).
When I deploy this application on the test server, I have the error 400 Bad Request below:
Bad Request
Your browser sent a request that this server could not understand.
I accessed to the website with the normal URL.
I'm using symfony 1.4 with doctrine (no others plugins are involved), wamp 2 (php 5.3, apache 2.0.59).
If I try to access the application with the dev environment, it works.
Try checking if the no_script property on your application setting.yml file. If should be set to False, clear cache and try again
Thank you very much Guiman. You have leaded me to the answer.
The no_script_name property wasn't the origin of the problem. Instead, I have my .htaccess in the web directory which was badly generated (I swear on my pet's head that I haven't edited this file before). Below is the file generated by symfony (the bold attribute isn't working within the code one, look at the last line):
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
And this is the updated one (again, look at the last line):
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ **/myApp/index.php** [QSA,L]
</IfModule>
I don't know what happened but I will check on the symfony website I there are similar issues.

Rewriting rails url from port 3000?

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.

Resources