So I've just upgraded to Laravel 4, and I'm setting things up on a new server. The default / route works fine, but every other route returns a 404 error. When trying index.php/route, I get the requested data, so that means that .htaccess isn't working.
Yes, AllowOverride is set to ALL.
Yes, I enabled the mod_rewrite module.
I have tried the following 3 .htaccess combinations:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
and:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
And, after a server restart, and so on, none of them are working, and I'm still returning a 404 error.
Note: I am using several domains with the same laravel install, so my public folders are public/site1, public/site2, public/site3. However, I am routing the public paths to these folders, so I'm not sure that would be the problem.
Any thoughts?
I forgot to edit the vhosts in httpd.conf. Derp, derp.
Added:
<Directory "/var/www/public/site1">
AllowOverride All
</Directory>
to each of the site's vhost files, and it worked beautifully. Derp derp.
Related
I am using CodeIgniter 4.1.3.
below is my .htaccess
#Options All -Indexes
<IfModule mod_rewrite.c>
#Options +FollowSymlinks
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
ServerSignature Off
options all and followSymlinks not supported on server.
Working fine on localserver
Front page is loaded but it is not loading css,javascript and image from public directory giving 404 error.
not sure what need to be change.
With your shown samples, please try following htaccess Rules file. Make sure to place this in your root directory. Also make sure to clear your browser cache before testing your URLs.
Options -Multiviews
<IfModule mod_rewrite.c>
#Options +FollowSymlinks
RewriteEngine On
RewriteBase /public/
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php/$1 [L,NC,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
ServerSignature Off
JS/CS rewrite/redirect: You may need to use base tag to fix your js and other relative resources. If you are linking js files using a relative path then the file will obviously get a 404 because its looking for URL path. for example if the URL path is /file/ instead of file.html then your relative resources are loading from /file/ which is not a directory but rewritten html file. To fix this make your links absolute or use base tag. In the header of your webpage add this <base href="/"> so that your relative links can load from the correct location.
Options All -Indexes
Options +FollowSymlinks
works well on apache but if your server is centos then use this
Options -Indexes
Options +SymLinksIfOwnerMatch
Please help, I've read a lot of posts about this issue, nothing helps.
I have yii2 installation under: c:/sites/mysite
The index.php file is in: c:/sites/mysite/web
I have htaccess file under c:/sites/mysite that looks like this:
# turn on rewrite engine
RewriteEngine on
RewriteBase /
RewriteRule ^index.html?$ home.php [NC,R,L]
DirectoryIndex home.php
# on what should it skip the rules
RewriteRule ^(favicon.ico) - [L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Do not allow calls from servers testing ou server fi were a proxy
# http://serverfault.com/questions/499125/banning-all-azenv-php-request-to-my-server
#RewriteCond %{HTTP_REFERER} .*/azenv\.php [NC,OR]
#RewriteRule .* - [F]
#RewriteCond %{HTTP:X-Forwarded-Proto} !https
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
# otherwise forward it to index.php
RewriteRule . index.php
I have my-vhosts file that has this code:
ServerName armanager
ServerAlias armanager
DocumentRoot "c:/sites/armanager/web"
Options Indexes FollowSymLinks
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
Going to mysite on firefox works fine.
I have a controller esController with actionSettings function.
I have a view settings.php
Going to mysite/es/settings gives me the dreaded 404 Not Found error.
Can you please help?
Ok, I added this .htaccess in the web folder:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</IfModule>
Now, everything works.
I have seen several other threads about this but for some reason in my specific case the solutions are not working.
Here is the .htaccess
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks -Multiviews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1
The desired effect is that index.php will load what ever page is requested in the GET (/events-diary = index.php?page=events-diary) & that works fine.
However I have some REAL directories which need to be accessible for example /admin/
The above .htaccess works perfectly fine as desired on my home computer MAMP, it works perfectly fine on my Amazon Micro, it will not work on the deployment server ipage.com
When you enter /admin it will redirect to the root index. When you type /admin/index.php it works, but you have to specify the index.php
I cant figure out when it seems to be ignoring the !-d
UPDATE:
index.php contains the following PHP
if(!isset($_GET['page'])){
header("Location: home");
exit;
}
$line=page_content($_GET['page']);
note that this functions fine on the other 2 servers, i dont see why it would behave differently on the 3rd.
Use:
Options +FollowSymLinks -MultiViews -Indexes
With -MultiViews with uppercase V.
For Apache, in some cases upper/lower case are very important
Here is a different set of rewrite rules that might work for you:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1 [NC,L]
Are you trying to route things to /admin/index.php? If so, you could create a copy of your .htaccess, upload it to the /admin directory and set the RewriteBase to /admin.
or, if you wanted to turn the rewrite engine off in your /admin directory, you could create an .htacess file that contains:
RewriteEngine off
Difficult to post these suggestions in comment so resorting to an answer.
Try this rule:
ErrorDocument 404 default
ErrorDocument 403 default
DirectorySlash On
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks -Multiviews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/$1 !-f
RewriteCond %{DOCUMENT_ROOT}/$1/ !-d
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]
Got flamer script (http://provenlogic.xyz/flamer) installed and configured but start to get problem just in Opera and Chrome (in Firefox and IE works fine).
Here is my installation http://chronogym.com/flamer
The same url causes endless loop in Chrome and Opera and works fine in FF.
First question is how it could depend on browser, because I thought that redirections are driven only by server side.
Another question: when adding something like dd('test'); somewhere in controller even in FF script begins to brake connection instead of showing dumping result.
Project is placed in subdir on server: root/flamer. In root I got other project. I suggest that .htacces from that project can cause problems or conflicting with .htaccess from flamer but can't find out the exact cause.
root .htaccess
ModPagespeed off
RewriteEngine On
RewriteBase /
#Options +FollowSymlinks
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(_css|_js|memberarea)/
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
ErrorDocument 404 http://www.chronogym.com
RedirectPermanent /coaching.php http://chronogym.com/2-0-coaching_minceur.html
subdir .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.chronogym.com/flamer/$ [NC]
RewriteRule ^(.*)$ http://chronogym.com/flamer$1 [R=301,L]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Your middle rule is not correct but that would conflict anyway. You need to use RewriteBase if this .htaccess file is in the flamer folder. Have your rules like this.
RewriteEngine On
RewriteBase /flamer/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I've setup a new install of Laravel on my local. It appears there are issues with htaccess or Apache settings. I've researched for a number of hours and tried everything I read.
OSX Lion 10.7.5
MAMP 3.0.5
PHP 5.5.10
mod_rewrite is being loaded.
My development server works with other sites. This is the first time I am trying Laravel 4.
I get a 403 Forbidden on the welcome page which is located at website.dev:8888/
Apache gives me this error: Directory index forbidden by Options directive
Here is my .htaccess file content:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Here are a few additional actions I've taken:
AllowOverride is set to All in httpd.conf
Added virtual host code section to httpd-vhosts.conf
verified that the hosts file contains a line for the site 127.0.0.1 website.dev
I've also tried various lines in the htaccess which I found in articles and I also restarted apache each time I made changes to the conf files. No routes work. When I go to website.dev:8888/public I get a blank page, no error. If I go to a route I created such as website.dev:8888/users I get a 404 not found error.
Thank you for your help!
This solution worked fine, best solution ever for me. Paste this code into root htaccess. That's all. Leave all other files as they are
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</IfModule>
In the root path create a .htaccess file with
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/$1
#RewriteRule ^ index.php [L]
RewriteRule ^(/)?$ public/index.php [L]
</IfModule>
In public directory create a .htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
if you have done any changes in public/index.php file correct them with the right path then your site will be live.
what will solve with this?
Hosting issue of laravel project.
Css not work on laravel.
Laravel site not work.
laravel site load with domain/public/index.php
laravel project does not redirect correctly
Answer
Heres what I found that worked. Delete the .htaccess file inside the /public directory and then put the following into the laravel installation's document root.
Clarification
So for clarification if your laravel application is installed at /public_html/laravel you will look inside /public_html/laravel/public and delete the .htaccess file there. Then inside the /public_html/laravel directory make a new file called .htaccess
Copy the code below to a new .htaccess file in the doc root
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /public/$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
</IfModule>
Please note
As Concordus Applications noted in their answer here make sure that the Loadmodule mod_rewrite is uncommented (make sure there is not a # symbol behind it in your apache config file)
Concordus Applications also noted that you should have AllowOverride set to the appropriate setting. The example they gave was the following.
<Directory "/some/absolute/path/htdocs">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
Please make sure to restart your apache server if you made any changes to your apache config file.
The accepted answer worked but not with laravel passport authentication.
There is a need to add some header tweaking:
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.
If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Make sure you have .htaccess files in both /wwwroot and /public. The content is different though:
wwwroot/.htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/$1
#RewriteRule ^ index.php [L]
RewriteRule ^(/)?$ public/index.php [L]
</IfModule>
wwwroot/public/.htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This .htaccess will remove /public/ from your URL and force https://
Put this .htaccess in your root folder without renaming server.php file to index.php
this .htaccess will do everything
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^(.*)$ public/$1 [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Simple Solution Copy and Paste The Code Below Into Your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteRule ^-$public/index.php[L]
RewriteRule ^((?!public/).*)$ public/$1 [L]
</IfModule>
Create new .htaccess file in root folder.
and put this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</IfModule>
and add this code in .htaccess at end in public/.htaccess file
RewriteCond %{THE_REQUEST} \s/+(.+/)?public/(\S*) [NC]
RewriteRule ^ /%1%2? [R=301,L,NE]