I have recently installed the lamp stack and have enabled mod_rewrite:
$ sudo a2enmod rewrite
$ service apache2 restart
I can see it on my phpinfo:
But when I try to access an URL like this below in my WordPress:
http://my-localhost/my-wordpress/whats-on/
I get this error:
Not Found
The requested URL /my-wordpress/whats-on/ was not found on this
server.
Apache/2.4.18 (Ubuntu) Server at 127.0.0.1 Port 80
What else can I do? Have I missed anything?
Any ideas?
I have my .htaccess on too:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my-wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /my-wordpress/index.php [L]
</IfModule>
# END WordPress
But why?
EDIT:
I created a simple test:
RewriteRule ^test.html$ test.php [L]
But i get 404 error instead of being directed to test.php
Not Found
The requested URL /mod_rewrite/basic/test.html was not found on this server.
Apache/2.4.18 (Ubuntu) Server at 127.0.1.1 Port 80
How can I fix this?
To fix this issue follow this:
sudo nano /etc/apache2/apache2.conf
Find:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Replace With:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Exit and save and restart apache with command
sudo systemctl restart apache2
THE END :-)
Related
On Ubuntu I've installed Laravel and PHP.
But when I type ip of my server in the browser I can see only files and folders.
Ubuntu 16.04, php 7.4, apache2
This is my folder /var/www/html/myproj/:
root#srv:/var/www/html/myproj# ls
CHANGELOG.md bpl laradock routes webpack.mix.js
README.md composer.json package.json server.php
app composer.lock phpunit.xml storage
artisan config public tests
bootstrap database resources vendor
What I have to do yet?
This is laravel.conf file that is in /etc/apache2/sites-available:
<VirtualHost *:80>
ServerName yourdomain.tld
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/myproj/public
<Directory /var/www/html/myproj>
AllowOverride All
<RequireAll>
Require ip 127.0.0.1 xxx.xx.xx.xx
</RequireAll>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess looks like this:
<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>
Assuming you are using Apache2, there are several things to do.
First, try to open the public path in your browser, for example : http://localhost/public
If the problem remains, verify in your server configuration that .htaccess file are handled, this property must be set in the apache2 configuration :
AllowOverride All
Here is an example with the default web server folder :
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
In general this value is set to None by default, so change it to All.
But, to be sure you can do that, you must have activated the mod_rewrite extension, so in linux terminal type this :
sudo a2enmod rewrite
sudo service apache2 restart
configure the nginx vhost file to point /public folder & also add laravel rewrite rule in vhost file
If you are using nginx try settings below:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
root /var/www/html/myproj/public;
}
This is my .htaccess file. I am used Codeigniter Framework for my project.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Where is my mistake here? But It Works in xampp.
You can't just move from one server to another and not make sure your prerequistes are there. These things are not on by default on most systems. You also have not given any specifics about your setup or even your document root.
So going off that it's an Ubuntu server and apache2, you need to do these things.
First thing you need to do if this is a new LAMP install is make sure rewrite is on.
Run this command to enable mod_rewrite.
sudo a2enmod rewrite
Then you need to make sure you allow .htaccess in your document root.
edit
/etc/apache2/sites-available/000-default.conf
In this file search for this
AllowOverride None
and change it to
AllowOverride All
Then restart apache2.
sudo service apache2 restart
EDIT: Based on your comment, you need to make your vhost look like this and then restart apache2.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
AllowOverride All
</Directory>
</VirtualHost>
Open your terminal
Run this following code:
sudo nano /etc/apache2/apache2.conf
go down and change:
AllowOverride All
look like:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Then restart apache2.
sudo service apache2 restart
and then .htaccess file is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Are you sure mod_rewrite module is loaded ? go to httpd.conf and search for -
LoadModule rewrite_module modules/mod_rewrite.so
and make sure theres no # [hash tag] before
I am following the quickstart of laravel and it said "type /users" but not working for me.
I have wrote in the browser, http://DomainServer/ProjectName/users and it throws:
The requested URL /ProjectName/users was not found on this server.
Laravel
I tried the following,
To enable the apache module mod_rewrite and also does not work.
Steps for Apache Web Server and Laravel in Linux Environment.
Open httpd.conf
sudo vim /etc/httpd/conf/httpd.conf
# for debian users: /etc/apache2/apache2.conf
Make sure the DocumentRoot is pointing to the laravel project's public directory
Add the Directory element for that path and Allowoverride All... as follows
DocumentRoot "/var/www/html/laravel/public/"
<Directory "/var/www/html/laravel/public">
Allowoverride All
</Directory>
Open .htaccess from ../laravel/public/ and make sure it has the following
<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>
Restart httpd services
sudo service httpd restart
Now http://DomainServer/users will work in your browser.
Find httpd.conf and change the <Directory> element from
<Directory "/var/www/html/">
Allowoverride None
</Directory>
to
<Directory "/var/www/html/">
Allowoverride All
</Directory>
Then it works after restart the apache without change the DocumentRoot.
First find the htaccess file in your Laravel project
next add the following coding in htaccess file
<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]
save the htaccess file
and restart the apache server using following code
sudo service apache2 restart
remember htaccess file and index.php file must be available in same folder in your project
the default url have a prefix "index.php" before your page if you try .../public/index.php/your_page it will run, so you need to add the module rewrite if you are using appache to write your url without this prefix
Try pointing your browser to http://DomainServer/ProjectName/public/users - the 'public' folder is the default 'entry point' for your Laravel app.
Make sure you have mod_rewrite enabled in Apache .
For me i enabled the mod_rewrite and it worked for me well.
Enable mod_rewrite for Apache:
cd /etc/apache2/sites-available/
sudo a2enmod rewrite
in my case I wanted to get this route as not authenticated user .
RouteServiceProvider has default :
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* #return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
which means you need to add that prefix "api/" to your url, say:
http://yourdomain.com/api/route_url_part
Then put route to api.php , not web.php wich is auth 'middlwared'
(optionally for Android emulators)
if you are trying to do that in, say, android emulator you have to shut down server and start it as:
php artisan serve --host=0.0.0.0
and in java android url instead of localhost put in the ip retrived from prompt window's ipconfig command. Say mine was 192.168.0.106
(IPv4 Address one). Then it will work.
$ sudo nano /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
Change to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
$ sudo a2enmod rewrite
$ sudo systemctl restart apache2
This has got me baffled. I recently set up VM in a hurry to go travelling. I installed Ubuntu 12.04 and LAMP. The PHP version is 5.5 and Apache is 2.4. I have used this same configuration on my home machine and it works fine.
Anyhow, the problem is that I can only access actions on the index controller of my ZF application, e.g: domainname/, domainname/index/info. If I try any other controllers, e.g. domainname/test/view, I get the apache 404 error. (Note - NOTE the ZF Not Found error).
I imagine this is a problem with URL rewriting, but the .htaccess on my VM is the same as my home machine, and I can't see anything in the virtual host configuration that would cause this. Also, if it was simply an URL rewriting problem, I would have thought it would come in to play for ALL urls, including the index controller...
Here's my htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Ideas?
EDIT: Here's the virtual host config:
DocumentRoot /home/kim/www/vhost/public
ServerName koop
SetEnv APPLICATION_ENV "development"
<Directory /home/kim/www/vhost/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Ok, so I had to change AllowOverride to All. That means Apache2 will now process my .htaccess files.
Then I needed to enable mod rewrite, by sudo a2enmod rewrite, then restart apache, i.e. sudo service apache2 restart
codeigniter .htaccess in amazon ec2 removal of index.php not working
code
RewriteEngine on
RewriteBase http://ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
config file
$config['base_url'] = 'http://ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com/';
You can change your .htaccess like this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
and change the value of "AllowOverride None" on /etc/httpd/conf/httpd.conf (if you use AMI Linux)
into "AllowOverride All"
after that restart your apache with command like this:
sudo service httpd restart
It's work and tested on my aws ec2.
(if you use ubuntu)
Activate the mod_rewrite module with
sudo a2enmod rewrite
and restart the apache
sudo service apache2 restart
To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with
sudo nano /etc/apache2/sites-available/000-default.conf
Search for “DocumentRoot /var/www/html” and add the following lines directly below:
<Directory "/var/www/html">
AllowOverride All
</Directory>
Save and exit the nano editor via CTRL-X, “y” and ENTER.
Restart the server again:
sudo service apache2 restart
Justudin is correct!
Also you can use the "AllowOverride All" rule to only your project; writing in /etc/httpd/conf/httpd.conf something like this:
<Directory "/var/www/your_website">
AllowOverride All
</Directory>
Only you can use the "AllowOverride All" rule to all deployed application; writing in /etc/httpd/conf/httpd.conf :
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>