I'm trying to make simple routing with php using apache. This is my .htaccess file:
`
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
'
This is my index.php :
<?php
echo "request = " . $_SERVER['QUERY_STRING'];
Also i got test.php in directory.As far as i understand it should redirect all requests that is not an existent files ot folders. All works fine for random request and works directly for localhost\test.php. But once i try localhost\test or localhost\test\new It doesnt get redirected to the index.php. The requested URL /test/new was not found on this server. What do i miss?
And there is my apache settings:
<Directory /var/www/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Related
I want to deploy my laravel project on an Ubuntu server but it only shows the welcome page. I tried to login and it keeps telling me that the URL is not found on the server. I already modified my conf file in apache:
Alias /hris/imiforms /var/www/apps/hris/imiforms/public
<Directory /var/www/apps/hris/imiforms>
Option Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
and I my .htaccess file is shown below.
It has rewrite Engine all and I already executed apache restart command. Can you help me and telling me what is wrong?
<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
RewriteCond %{REQUEST_FILENAME} !—d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ $1 [L,R=30l]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I see in your apache configuration an alias, but you don't use it.
You need to set your full directory like that, or use the alias defined before instead of full path:
<Directory /var/www/apps/hris/imiforms/public>
...
</Directory>
The /public part is very important because it is the Laravel entry point.
I enabled mod_rewrite and checked it with phpinfo().
I placed a .htaccess file with
RewriteEngine on
RewriteRule ^(.*)$ index.php?/$1 [L]
and a index.php file at apache root directory (/var/www/html/).
Working URL:
http://192.168.56.101/index.php
http://192.168.56.101/index.php/edrgderg
Failing (404) URL:
http://192.168.56.101/sgghsshgfhfgj
Mod_rewrite should form this to http://192.168.56.101/index.php/sgghsshgfhfgj , but it doesn't.
I want to redirect each request to index.php.
SOLUTION:
I had to edit my apache configuration:
sudo nano /etc/apache2/sites-enabled/000-default.conf
I added:
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
As sugested here: https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04
Exclude existing files/directories from your rewrite rule to avoid looping the rules:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?/$0 [L,QSA]
For few days i've been searching how to resolve this issue, but nothing helped.
I have laravel project c:/wamp/www/laravel/public and only the default route is working(anything i put in it it will work), but any other route is not.
These two routes i have at the moment. First one works, second one not.
Route::get('/', function () {
return view('page.home');
});
Route::get('/shows', function () {
return view('page.shows');
});
I tried many things in .htaccess, httpd.conf, httpd-vhosts.conf that i found on the internet but nothing works.
I've enabled rewrite_module in httpd, i've tried adding virtual host to ti or httpd-vhosts:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName autoplay.dev
<Directory "c:/wamp/www/laravel/public">
Options FollowSymLinks Indexes Multiviews
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
This is my .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine on
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
In it i tried RewriteBase as well but it didn't help.
Now when i try to go to any other page except home page(it's the same if i have a route or not) i get error NOT FOUND: The requested URL /wamp/www/laravel/public/index.php was not found on this server.
Please don't ask if views are in page folder and similar questions, that is correct because it's working if i switch it in default route.
Can you please help me because i've been searcing and trying for few days and this is bad for my health :D
Thanks :)
In your virtual host file,
<VirtualHost *:80>
DocumentRoot c:/wamp/www/laravel/public
ServerName autoplay.dev
</VirtualHost>
Use below code in your .htaccess file:-
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Now check autoplay.dev/ in your browser.
Link:- https://laravel.com/docs/5.0/installation#pretty-urls
Check this link also.
Hope it will help you :)
My front url is-
http://localhost/myProject/
admin url is -
http://localhost/myProject/admin
It works in windows but not works on Ubuntu.
It gives error "Not found".
What works in ubuntu -
The front page is working - http://localhost/myProject/
The admin login page is working if I add index.php in url like this -
http://localhost/myProject/index.php/admin
Not other pages are working
My .htaccess file contents-
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|themes)
RewriteRule ^(.*)$ /myProject/index.php/$1 [L]
My Apache's mod-rewrite module is on.
I was also following the similar issue in Centos, and I followed the below tutorial :
How to permit changes in the .htaccess file:
open httpd using ------------------> vi /etc/httpd/conf/httpd.conf
Once inside that file, find the following section, and change the line that says AllowOverride from None to All. The section should now look like this:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
After you save and exit that file, restart apache. .htacess files will now be available for all of your sites.
service httpd restart
Content of .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
RewriteEngine on
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /
# Restrict your site to only one domain
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|fonts|js|images|robots\.txt|css)
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
#prevent access to htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
#disable directory browsing
Options All -Indexes
IndexIgnore *
i have read posts regarding this but that did not gave answer to my problem
i have set everything i found on forums of code igniter and SO's questions
currently i have following settings :
.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|(.*)\.swf|images|robots\.txt|css|docs|cache)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /application/errors/404.php
</IfModule>
and i also have set $config['index_page'] = '';
but this is not working there is not change in URL
if i type *http://localhost:8088/crud_demo/index.php/login* it works but if i type *http://localhost:8088/crud_demo/login* it shows Not Found Error
My Route config
$route['register'] = "register";
$route['manage'] = "manage";
$route['default_controller'] = "login";
$route['404_override'] = '';
Change AllowOverride None to AllowOverride All in my virtual host file at /etc/apache2/sites-available/000-default.conf in ubuntu
Change AllowOverride None to AllowOverride All in my virtual host file at /etc/apache2/sites-available/default.conf in windows
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All <---- replace None with All
</Directory>
<Directory /var/www >
Options Indexes FollowSymLinks MultiViews
AllowOverride All <--- replace None with All
Order allow,deny
allow from all
</Directory>
....
Then put this code in .htaccess file in root folder in codeigniter
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
It will definately work.
RewriteRule ^crud_demo/(.*)$ crud_demo/index.php/$1
http://martinmelin.se/rewrite-rule-tester/ to test URL rewrites.
I think CodeIgniter has it's own way of routing URLs like other PHP frameworks. Take a look here: http://codeigniter.com/user_guide/general/routing.html
If crud_demo is a subfolder of your root dir then you should change
RewriteBase /
to
RewriteBase /crud_demo