laravel 5.1 only routing to home page, all other routes are coming 404 not found error, after hosting the local working site to the server - laravel-5.1

I have pushed my laravel 5.1 application to server. In localhost, it works properly. but in server , only the home page is coming, no other routes working. I get 404 not found not found error. jQuery-2.1.4.min.js:4 POST http://mydomainurl/login/validate_login 404 . I feel, it should traverse to http://mydomainurl/applicationName/login/validate_login. I dont know whats happening and where i have to update.
I have enabled mode rewrite in apache and my .htaccess of application's public/ directory is as below
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteCond %{REQUEST_URI} !^ RewriteRule ^(.*)$ /$1 [L] </IfModule>
I dont know much about .htaccess, but i copied from someone's answer. Please help

After doing all the above modifications,And surfing around net, it didnt work. Finally i understood that it may be because of url problem and just changed the url in ajax, like url: "<?php echo url();?>/login/validate_login", It started working amazingly. Only in local host simply, url: "login/validate_login", works.
Over all, things to be done are:
1: move public folder contents to your server's root folder(name it anything, eg: var/www/html/my_public). Update the .htaccess and index.php of it as explained in other answers. modify server.php, bootstrap/app.php if still didnt work. use url() with the calls. I achieved with this much :-)

The problem is probably caused by your virtualhost config file. It should have "AllowOverride All" directive^
<VirtualHost *:80>
ServerAdmin youremail#yahoo.com
ServerName yoursite.com
ServerAlias www.yoursite.com
DocumentRoot "/var/www/yoursite.com/public"
<Directory /var/www/yoursite.com/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

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]

www to http resolve for Rails app on passenger

I am running a rails app on phusion passenger. I want to resolve all www addresses to http for SEO benefits.
I am using phusion along with the apache server and for performance benefits would like the redirect to be in the httpd.conf file instead of the .htaccess file. I added the redirect in the httpd.conf file but it redirects to the public folder of the application on every url request. I wrote to my hosting provider and got the following response:
Since passenger is configured for your rails application via .htaccess, the direct rules through htaccess will not work. But, htaccess directs will work fine with non rails applications.
If you really wish to redirect www.xyz.com to xyz.com, you have to add a code similar to the following in your application.
-------
before_filter :check_uri
def check_uri
if /^www/.match(request.host)
redirect_to request.protocol + request.host_with_port[4..-1] + request.request_uri
end
end
I think this is not good for performance of the application. Is there any way I can redirect from the httpd.conf file itself?
Here is the httpd.conf file:
This redirects www to the public folder instead of http
<Directory "/home/xyz">
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</Directory>
<VirtualHost 1.1.1.1:80>
SuexecUserGroup "#500" "#501"
ServerName xyz.com
ServerAlias www.xyz.com
ServerAlias webmail.xyz.com
ServerAlias admin.xyz.com
#DocumentRoot /home/xyz/public_html
DocumentRoot /home/xyz/public
DirectoryIndex index.html index.htm index.php index.php4 index.php5
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.xyz.com
RewriteRule ^(.*) https://xyz.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.xyz.com
RewriteRule ^(.*) https://xyz.com:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824
<Files awstats.pl>
AuthName "xyz.com statistics"
AuthType Basic
AuthUserFile /home/xyz/.awstats-htpasswd
require valid-user
</Files>
Alias /dav /home/xyz/public_html
<Location /dav>
DAV on
AuthType Basic
AuthName "xyz.com"
AuthUserFile /home/xyz/etc/dav.digest.passwd
Require valid-user
ForceType text/plain
Satisfy All
RemoveHandler .php
RemoveHandler .php5
RewriteEngine off
</Location>
</VirtualHost>

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.

Redirecting www to non www on server with wildcard subdomains

I have a Rails+Apache+Passenger setup and my app serves wildcard subdomains. I need all www URLs to redirect to their non www equivalents.
www.example.net should redirect to example.net
www.subdomain.example.net should redirect to subdomain.example.net
My current vhost config is as below
<VirtualHost *:80>
ServerName example.net
ServerAlias *.example.net
DocumentRoot /home/public_html/example.net/current/public
RailsEnv staging
</VirtualHost>
I tried an assortment of rewrite rules in various locations but none took effect. I've checked to make sure that the apache rewrite module is enabled and RewriteEngine is on. Not sure what I'm missing. All help much appreciated!
I solved this issue in my app, as I have logic based on the domain anyway. Place this code in your ApplicationController
class ApplicationController < ActionController::Base
before_filter :check_host
def check_host
if request.host.split('.')[0] == 'www'
redirect_to "http://" + request.host.gsub('www.','')
end
end
end
Could have special cases if some of your hostnames contain "www." for any other reason that you'd have to code for.
You can use moderewrite in your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.net [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} ^www\.subdomain\.example\.net [NC]
RewriteRule ^(.*)$ http://subdomain.example.net/$1 [R=301,NC]
This should work in but I not test it.
or this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]

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