Apache redirect is failing for Laravel - apache

I have mod_rewrite enabled on Apache2 and AllowOverride All in the default file. However Apache (After restarting) still can't seem to redirect when given a pretty url from Laravel.
WORKS (Returns: Users!): localhost/laratest/public/index.php/users
DOESN'T WORK (404): localhost/laratest/public/users
My .htaccess: (I've also tried the one suggested in the Documentation to no avail)
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Laravel routes.php:
Route::get('/', function()
{
return View::make('hello');
});
Route::get('users', function()
{
return 'Users!';
});
I am using the default LAMP stack and configuration in Ubuntu. Any ideas why this isn't working?

Have you set your RewriteBase to /laratest/public?
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /laratest/public
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

As suggested on the laravel website (http://laravel.com/docs/installation#pretty-urls) try this other one:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Related

How to fix mod_rewrite problem with static to dynamic content

I would appreciate if someone can help with this mod rewrite issue. For years I had this in my htaccess, apache include files and it worked just fine.
RewriteRule ^/article/([0-9]*).html$ /article/article.php?id=$1 [NC,L]
But recently it stopped working. Browser shows "No input file specified." and access log shows 404 response code the requests that had to be fulfilled by the condition above.
RewriteEngine is on. This is what my htaccess mod_rewrite rules at the moment
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /404error.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^/article/([0-9]*).html$ /article/article.php?id=$1 [NC,L]
RewriteRule ^/relationships/([0-9]*).html$ /article/article.php?id=$1 [NC,L]
</IfModule>
With your shown samples/attempts, could you please try following htaccess Rules. Please make sure to place your htaccess rules file in root and clear your browser cache before testing your URLs.
<IfModule mod_rewrite.c>
Options -MultiViews -Indexes
RewriteEngine On
RewriteBase /
##Rules for non-existing pages.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
##Rules for articile and relationship uris here.
RewriteRule ^(?:article|relationships)/([0-9]*)\.html/?$ article/article.php?id=$1 [NC,L]
##Rules for 404 handling.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) 404error.php [L,NC]
</IfModule>

.htaccess redirect URL with loaded css, js and image

I am trying to rewrite the URL from the .htaccess file, tried a lot but ended up with frustration.
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ^suba/?$ resources/uploads/releases/zipfiles/1484883480/index\.html [NC, C]
RewriteRule ^ index.php [L]
I just want to open this with the short URL like this to make it more SEO friendly,
http://dittmagasin.no/release.
I have referred to the following posts:
URL rewriting with PHP
URL rewriting for beginners
Any help will be appreciated.
Thanks
You can use:
RewriteEngine On
RewriteRule ^release/?$ resources/uploads/releases/zipfiles/1484883480/index.html [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

.htaccess the requested url /public/index was not found on this server

Hello there i just finished setting up my server and all my code files but im having a problem. Whenever i go to https://www.frindse.com/index it gives me a error that says that the /public/index file is not found.
The way my site is setup is all the requests goes to the public folder which holds my index.php file that routes all of my pages. Not on my local server everything works flawlessly but on my digitalocean server whenever i go to the index page it doesn't works. But if i go to https://www.frindse.com/login the pages loads perfectly. So this is how my .htaccess file looks in my public folder which routes all my pages and requests:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Also here is the .htaccess file thats in the root of my website. It routes all the calls to the public folder:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
Also keep in mind that i have mod_rewrite activated on my server and also i have set AllowOverride set to All in my digitaloceans erver.
Try adding a rewritebase to your .htaccess in public folder. And turn off multiviews for good measure.
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Actually, why do you even need an .htaccess file in public folder? Just route the request directly to the index file like this .htaccess file in your root and remove the the one in public folder.
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteRule ^$ public/ [L]
RewriteRule ^(.*)$ /public/index.php?url=$1 [QSA,L]
</IfModule>

htaccess is supposed to remove index.php from current URL, but instead redirects to root

I've read been reading StackOverflow posts for the last 30 minutes and none of them work. Maybe there is a server setup that is preventing this from working?
I just want to remove index.php from whatever URL is typed in. For example, www.mysite.com/blah/blah/index.php would become www.mysite.com/blah/blah/. www.mysite.com/index.php would become www.mysite.com/.
I've read at least 10 posts and tried each one, but it ALWAYS just redirects to the root. Here is the current code I'm using that looks like it should work:
Options +FollowSymLinks
Options +Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
Instead of just removing index.php from the URL, it redirects to the root of the site.
I think this is what you are looking for:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ $1/index.php [L,QSA]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
</IfModule>

RewriteRule isn't working

I'm trying to remove .php extension from .htaccess . I'm running Apache web server on Ubuntu . Have enabled mod_rewrite.c (module) and from virtual host configuration AllowOverride option as well
In .htaccess I've following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
</IfModule>
Which goes to 404 , but if just try to redirect from specific file to anywhere it is working , that's makes me think that I've problem with code written above , any suggestions ? thanks ...
Options +FollowSymLinks
RewriteEngine on
Options -MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Above code perfectly works for me. I am also using Apache web server on Ubuntu.