url not found error in laravel - apache

I am using Laravel 5 with a new version of apache on ubuntu and when I try to access the page: localhost it works and if I try localhost/index.php/my_page it works but if I try localhost/my_page, it doesnt. So from searching other questions I guess my problem lies in the .htaccess file.
As per suggestions I saw online I added the rewriteBase and Options +FollowSymLinks to my .htaccess in laravel/public:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /repos/kenrose/public
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and this is what my apache2.conf file looks
<Directory /repos/kenrose>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
I've taken all the suggestions i've found about this issue. What is the problem?

Try this:
<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]
Try to remove ur +FollowSymLinks part,hope it will work.

after running
a2enmod rewrite
in the command terminal, all is well.
I don't know what this does, or what the problem was though.

Related

Symfony 4 in subdirectory

I did install Symfony 4 on a subdirectory of my wamp localhost. My project is named "cardMaker".
I've a .htaccess file to redirect towards the public directory (index.php) :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule "^$" public/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . srcAngular/index.html [L]
</IfModule>
That works. But, when I open http://localhost/cardMaker/, I have this:
How can I set the base url ?
Here at https://symfony.com/doc/current/setup/web_server_configuration.html they say:
# If you run your Symfony application on a subpath of your document root, the
# regular expression must be changed accordingly:
# ProxyPassMatch ^/path-to-app/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/project/public/$1
Add the symfony app as an alias. Configure your apache httpd.conf file:
Alias /cardMaker "C:/Csi\CsiWorkspace/cardMaker/public"
<Directory "C:/Csi\CsiWorkspace/cardMaker/public">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
DirectoryIndex index.php index.html
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule cache/ - [F]
RewriteBase /symfonytest
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ ./index.php [L]
</IfModule>
</Directory>
Notice the use of RewriteBase for the alias cardMaker
This config (with php-fpm) currently works for me:
Apache: 2.4
Symfony: 3.4.44
<Directory /var/www/example.local>
Options Indexes FollowSymLinks
Allow from all
AllowOverride None
Require all granted
Order deny,allow
Deny from all
</Directory>
Alias /cardMaker /var/www/example.local/cardMaker/public
<Directory /var/www/example.local/cardMaker/public>
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
</Directory>
ProxyPassMatch ^/cardMaker(.*\.php(/.*)?)$ fcgi://php:9000/var/www/example.local/cardMaker/public$1

Run Laravel from subfolder using apache Alias

Im trying to run laravel from subfolder on my vps below is my configuration but it return too many redirect
apache alias
Alias /stockapp/ "/var/www/html/stockapp/public/"
<Directory "/var/www/html/stockapp/public/">
Order allow,deny
Allow from all
Require all granted
</Directory>
In public/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /stockapp
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

mod rewrite not working with laravel and bitNami

http.conf has mod rewrite uncommented
so no custom routes are working someone in #laravel mentioned it would be because mod rewrite isn't working here is my setup:
laravel.conf has the following code:
Alias /laravel/ "C:\BitNami/frameworks/laravel/public/"
Alias /laravel "C:\BitNami/frameworks/laravel/public"
<Directory "C:\BitNami/frameworks/laravel/public">
Options +MultiViews
AllowOverride None
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
</Directory>
If I uncomment these lines:
#RewriteEngine On
#RewriteRule ^/$ /laravel/ [PT]
then the main route will map to
http://localhost/
rather than
http://localhost/laravel
which is preferable but secondary to the main problem
.htaccess inside the public folder has this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /laravel
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
here is my test code inside routes.php:
Route::get('test',function(){
return 'test worked';
});
which should resolve with
http://localhost/laravel/test
but instead I get a 404 error
RewriteBase and RewriteEngine are defined twice. Make your .htaccess file look like this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /laravel
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
If possible, it would be best to use Apache virtual hosts instead.
Your .htaccess file should look like this.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)$ public/$1 [L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

How to hide php extension in url?

I am trying to remove php extension from url, But its not working for me. I am using Windows 7, with apache2.2.17 and php5.3. Now I have configured it as
in .htaccess file
OPTIONS -Indexes
IndexIgnore *
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
in httpd.conf enabled mod_rewrite as
LoadModule rewrite_module modules/mod_rewrite.so
and
<Directory "D:/Apache/htdocs">
Options Indexes FollowSymLinks ExecCGI MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
in php.ini
expose_php = On
After making these configuration still i am not able to remove php extension from url in my windows machine but same thing is working in ubuntu server.
Is there anything I am missing here?
This might answer your question:
RewriteRule ^/([^-]*)$ /$1.php
It works for root catalog.
RewriteRule ^catalog/([^-]*)$ catalog/$1.php
Or you can write automatic script:
RewriteRule ^/([^-])/([^-])$ /$1/$2.php
But this is for "httpd.conf" file.
Where: ([^-]*) means variable; $1, $2 means converted to variable i.e.
www.verity.com/foo/bar => verity.com/foo/bar.php
Use this instead:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php
By doing this, you will be able to call example.com/abc.php as example.com/abc

newbie trying to write url rewrite in .htaccess file

My site was under example.com/waha/.
Now I move the site right under the root example.com.
I want to 301 redirect all the old links like example.com/waha/notice/5803 to example.com/notice/5803.
How can I do it?
My current .htaccess file is below.
<IfModule mod_rewrite.c>
RewriteEngine On
# NOTE: change this to your actual StatusNet path; may be "/".
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?p=$1 [QSA,L]
</IfModule>
<FilesMatch "\.(ini)">
Order allow,deny
</FilesMatch>
Options -Indexes
Try this rule in front of your other mod_rewrite rule:
RewriteRule ^waha/(.*) /$1 [L,R=301]