Laravel default .htaccess file will not work - .htaccess

I finally got everything installed for Laravel, but I am getting an error 500 on my home page!
It looks to be my .htaccess file. If I remove it the page works. If I put it back, another error 500.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
If I change that second to last line to "RewriteRule ^index.php [L]" (no space before index.php) then the error 500 goes away but the rewrite rule will not work.
My host is 1and1.com.
Can anybody help me?

Changed this line:
RewriteRule ^ index.php [L]
to this:
RewriteRule ^ /index.php [L]
Now it works. Not only do I not get the 500 error, but the URLs appear to work as intended.

It seems to me the 500 internal error is coming because you have not set the virtual host in the apache httpd.conf file.
Put this line in the httpd.conf file
For windows
NameVirtualHost *:80
<VirtualHost *:80>
ServerName yourlaravel.com
DocumentRoot "C:/wamp/www/laravel/public"
<Directory "C:/wamp/www/laravel/public">
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www">
</Directory>
</VirtualHost>
For Linux
NameVirtualHost *:80
<VirtualHost *:80>
ServerName yourlaravel.com
DocumentRoot "/var/www/laravel/public"
<Directory "/var/www/laravel/public">
</Directory>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/var/www"
<Directory "/var/www">
</Directory>
</VirtualHost>
And to run it in your local machine
For window open the C:\Windows\System32\drivers\etc\hosts put this line.
yourserverip yourlaravel.com
For linux open the \etc\hosts put this line.
yourserverip yourlaravel.com
Your can refer to this link for further info:
http://net.tutsplus.com/tutorials/php/building-web-applications-from-scratch-with-laravel/
I hope this can be some help.

It work for me on the most of the project where default one won't work
DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>

create .htaccess file in your root folder then page the code bellow in the file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

I had a similar issue, and the error suddenly happened overnight.
I have searched all over google and Stackoverflow, but i couldn't find any solutions to fix this problem, and i kept getting a 500 Internal Server error.
I was on a shared hosting, and even renaming the .htaccess file didn't work.
At the buttom of .htaccess i put
php_flag opcache.enable 0
right before the ending </IfModule> . This solved the problem for me.

I also experienced this issue and solved it by commenting option line in .htaccess file..
Using apache 2.4.x
<IfModule mod_negotiation.c>
#Options -MultiViews
</IfModule>
It may conflicting with the site configuration.
Because it cannot have multiple condition with different operator.
I cannot find the link yet.
But I've read it somewhere before.
EDIT: Found the link.
Note
Mixing Options with a + or - with those without is not valid syntax and will be rejected during server startup by the syntax check with an abort.
Just make sure your .htaccess and apache configuration is not conflicting each other.

Related

change directory name in url only htaccess

I have a directory in my web root projectae/project/index.php and I want to change directory name only in url but in root still have the of projectae so I want to change
localhost/projectae/project/index.php
to
localhost/ae/project
I did some try on my htaccess but none succeed
I did try :
RewriteCond %{THE_REQUEST} ^GET\ /projectae/
RewriteRule ^projectae/(.*)$ /ae/$1 [L]
I also tried
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pojectae/project/$ /ae/project/$1 [L]
I did clear cache nothing work; I did restart apache nothing work
my config file :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
Your description suggests that you want to rewrite the other way round:
RewriteEngine on
RewriteRule ^/?ae/(.*)$ /projectae/$1 [L]
A typical combination would be to combine rules for redirection and rewriting:
RewriteEngine on
RewriteRule ^/?projectae/(.*)$ /ae/$1 [R=301,L]
RewriteRule ^/?ae/(.*)$ /projectae/$1 [L]
Those rules will work likewise in the http servers central host configuration or in a distributed configuration file (".htaccess" style file). If you really have to use such a distributed file then take care that it's consideration is enabled in your host configuration (see the documentation for the AllowOverride directive) and that above rule is placed in such a file inside the DOCUMENT_ROOT folder of the http host.

Return 404 for the /web directory Symfony 3

All my links are accessibles by mysite.com but also with mysite.com/web/
I would not like to redirect /web to / but, i would like to return a 404 for ^/web. I think it's possible cuz i saw a lot of symfony projects which return 404 error for the /web path
Thanks you all !
You need to modify your apache configuration so the document root points to /web folder.
Your apache config file needs to look something similar to this:
<VirtualHost *:80>
ServerName www.mysite.com
ServerAlias mysite.com
ServerAdmin contact#mysite.com
RewriteEngine On
DocumentRoot your_site_path/web
<Directory your_site_path/web/>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
</Directory>
</VirtualHost>

Symfony .htaccess DirectoryIndex not working

I am deploying my symfony application to production, i have placed the symfony application in the root folder
/var/www/html and have set the apache2 root directory to /var/www/html/web but the DirectoryIndex in the .htaccess file is not redirecting to the file app.php
On the url xxx.xxx.xx.xx/ i get the list of all the documents in /var/www/html/web folder, and if i do xxx.xxx.xx.xx/app.php the application loads.
I don't understand how to get the DirectoryIndex in the .htaccess to work.
I have been going through the following stack questions types but they don't work for me:
Redirect all requests to web/app.php in Symfony
Symfony: htaccess to hide app.php or app_dev.php
symfony2 rewrite rules .htaccess app.php
Another post suggested to set the apache2 root directory as /var/html instead of /var/html/web but that doesn't work either. Because the url xxxx.xxx.xx.xx/ deplays the content of the directory /var/html
The closest to a solution i came to was to rename the file app.php to index.php which got the root url xxx.xxx.xx.xx/ to load, but then all the 'sub' urls ( like xxxx.xxx.xx.xx/offer/9/Alternance_Apprentissage_graphiste_chez_Eggs) fails with a 404 Not Found error.
It is due to .htaccess file not redirecting properly the urls, because the url xxxx.xxx.xx.xx/app.php/offer/9/Alternance_Apprentissage_graphiste_chez_Eggs works fine.
My .htaccess file looks like this (it is the default generated file):
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
Any help appreciated. This is critical because i cannot get my application to go on production.
UPDATE
#shevron 's is right. From his answer "It is possible that .htaccess files are not parsed at all by your Apache setup." and "Check your main Apache configuration for AllowOverride on that directory. Try to set it to AllowOverride All and restart your Apache - see if that works."
I did the following:
I set my Apache Configuration as following :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/web
<Directory "/var/www/html/web">
AllowOverride All
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This did not work.
#shevron did i not write that properly?
But further i put all the configurations from the .htaccess file into the Main Apache Configurations as such and this made the redirection work:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/web
<Directory "/var/www/html/web">
AllowOverride All
Allow from All
</Directory>
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
So now the redirection is working.
It is possible that .htaccess files are not parsed at all by your Apache setup (in fact, this is probably recommended for single-tenant production servers for both performance and security reasons).
Check your main Apache configuration for AllowOverride on that directory. Try to set it to AllowOverride All and restart your Apache - see if that works.
If it works, I suggest moving the contents of your .htaccess file into a <Directory> or <VirtualHost> section in the main Apache configuration file (or better yet in a separate file included by it) and setting AllowOverride None.
I found this: http://symfony-check.org/permalink/optimize-apache-avoid-htaccess which is specific for Symfony with some details, although I don't know if its up-to-date as I'm not a Symfony user.

Drupal 7 rewrite not using .htaccess

I'm trying to enable the rewrite function in drupal 7 without using the .htaccess file since it should only be used if you do not have root access to the server (accordingly to apache's website)
Without any further adieu, here is my configuration
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DirectoryIndex index.php
DocumentRoot /var/www/example.com/public
ErrorDocument 404 /index.php
LogLevel warn
ErrorLog /var/www/example.com/log/error.log
CustomLog /var/www/example.com/log/access.log combined
<Directory "/var/www/example.com/public">
Options -Indexes +FollowSymLinks +ExecCGI
AllowOverride None
Order allow,deny
Allow from all
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
</Directory>
</VirtualHost>
The rewrite configuration worked when I had it in the .htaccess file but not when I put it inside the vhost file.
Can you guys see anything wrong here?
I think your rewrite rule should not contain the '/' prefix now that it's not a .htaccess anymore. Soo try with:
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Removing .htaccess reference is a good idea. You should put the AllowOverride None on a <Directory /> instruction so that this start from the root of the filesystem. If think you do not need the +ExecCGI also. If you want to go deeper in apache config for Drupal without .htaccess check also this detailled resource.

mod_rewrite and .htaccess may not be running...or I'm an idiot

I've seen about 100 different mod_rewrite and .htaccess problems that people were having, but so far I've yet to run across a fix for my issue.
I set up a new computer macbook pro running 10.8.2. This isn't using MAMPP or anything like that, just the native install of Apache. Everything seems fine and seems identical to my other machine, but as far as I can tell url rewriting is not happening.
I've checked that the rewrite module is loaded...and it is, I've added Allow all and all that stuff to my various .conf files and nothing is working. I've just lost perspective on what to even try next.
I don't know if it matters, but I've enabled VirtualHosts and the site I'm working on does indeed load if you put the /index.php/ in the URL.
I'll post any code anyone needs to see, just let me know what you need.
here is the .htaccess file (that works on the other machine)
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
my virtual host
NameVirtualHost *:80
ServerRoot "/Users/admin/Sites/dir"
<VirtualHost *:80>
DocumentRoot mysite/awareness-thing
ServerName awareness.test.dev
</VirtualHost>
EDIT: Here is a gist to my httpd.conf file: https://gist.github.com/JoeCianflone/f580f7dd75d7e10f05a0
There seemed to be two issues going on:
I changed my .htaccess file to this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^.*$ index.php [NC,L]
and I changed my vhost.conf to this:
NameVirtualHost *:80
ServerRoot "/Users/admin/Sites/site"
<Directory "/Users/admin/Sites/site">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot 2403_awareness-campaign
ServerName test.awareness-campaign.dev
</VirtualHost>
Just a combo of issues that made this a large WTF moment for me.

Resources