How to fix permalinks not working with Vagrant and Wordpress? - php

I am using Vagrant to build up a little Wordpress development VM. When I select permalinks (postname) then the page from an article doesn't load. However, when I select the standard link (i.e page id) all is working good.
I've used the service PuPHPet to build the VM.
My settings can be found here
I am using Wordpress 3.9.1 and Apache2
I've enabled mod_rewrite be executing:
a2enmod rewrite
And my .htaccess file from Wordpress is as follows:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /svisa/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /svisa/index.php [L]
</IfModule>
# END WordPress
it has the following permissions and ownership:
-rw-rw-rw- 1 vagrant www-data 248 May 30 14:52 .htaccess
My virtualhost file for the site (/var/www/svisa/) can be found here.
from my host computer, I browse to the site via adress: http://wpdev-vm/svisa/
where wpdev-vm is the name of the vm.
Does anybody know what I am missing to make the permalinks work?

I solved the problem myself.
In the default apache configuration, under /etc/apache2/sites-enabled, where mine is called 15-default.conf
This was declared under the document root:
<Directory "/var/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
I had to change AllowOverride None to AllowOverride All. Thus you'll get the following:
<Directory "/var/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
After that, the permalinks started working.

The (correct) answer above says that you need to change AllowOverride None to AllowOverride All in your xxx-default.conf file found in the /etc/apache2/sites-enabled directory.
However, in my vagrant box (precise64) none of the allowOverride or <Directory /var/www/>... code was present to begin with in the default.conf file.
I ended up having to add all of it between the VirtualHost tags, like below:
<VirtualHost *:80>
# Other stuff
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And then having to restart apache, like below, for it to work.
sudo service apache2 restart

Related

Update .htaccess to reduce length of URL

I am sending a website live and I was getting a 500 internal Error.
So I have googled around and I have been able to find a solution.
I have added modifications to the code below.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/public/index.php
RewriteRule ^(.*)$ /public/index.php/$1 [L]
</IfModule>
The issue is that, when I enter an URL such as www.app.com, I obtain www.app.com/public/index.php
Is there a way to update the .htaccess so that requests made to www.app.com will be redirected to www.app.com/public/index.php without showing /public/index.php in the URL?
Try modifying /etc/apache2/sites-available/default (default location on most Linux distributions, yours may be different).
Change AllowOverride None to AllowOverride All so you should have:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www>
Options FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
Then restart apache with systemctl restart apache2.

Laravel rewrite not working

I'm trying to make htaccess rewrite work on apache2 ubuntu 17.04 however it won't work. what i'm trying to do is access the route with localhost/anyroute but the only way to access it is localhost/PROJECTNAME/public/anyroute. localhost/ANYROUTE works on windows but apache will return "The requested url not found" on ubuntu and i have no idea why.. here are my confs file
.htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
my vhost
<VirtualHost *:80>
DocumentRoot /var/www/html/test/public/
<Directory /var/www/html/test/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/test-error_log
CustomLog /var/log/apache2/test-access_log common
</VirtualHost>
apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
so bottom line is that localhost/anyroute won't work but localhost/project/public/anyroute will work. i have pretty much tried everything :/
Enabling mod_rewrite
Now, we need to activate mod_rewrite.
sudo a2enmod rewrite
This will activate the module or alert you that the module is already in effect. To put these changes into effect, restart Apache.
sudo service apache2 restart
We will need to set up and secure a few more settings before we can begin.
First, allow changes in the .htaccess file. Open the default Apache configuration file using nano or your favorite text editor.
sudo nano /etc/apache2/sites-enabled/000-default.conf
Inside that file, you will find the block on line 1. Inside of that block, add the following block:
/etc/apache2/sites-available/default
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Your file should now match the following. Make sure that all blocks are properly indented.
/etc/apache2/sites-available/default
<VirtualHost *:80>
<Directory /var/www/html>
. . .
</Directory>
. . .
</VirtualHost>
To put these changes into effect, restart Apache.
sudo service apache2 restart
Now, create the .htaccess file.
For Detail Follow Below Reference Link :
https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04

Mod Rewrite EC2

I have followed instructions in another SO post to enable mod_rewrite on EC2. I have this setup:
# Configure /var/www/html
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
DirectoryIndex index.html index.php
Order allow,deny
Allow from all
</Directory>
RewriteEngine on
RewriteRule ^/?jobs$ jobs.html [L]
However when I visit http://example.com/jobs it fails to rewrite. I have checked with phpinfo() and mod_rewrite is enabled in PHP. What else could be preventing rewrite?

XAMPP httpd.conf setup to allow for mod_rewrite rules

I recently inherited a unfinished CodeIgniter project from a company that has sub-contracted me to complete it. I'm having some trouble with the mod_rewrite rules that the previous dev has implemented as I am unable to view the project on my localhost.
From what I can gather the rules applied are just to get rid of the "index.php" portion of the URL. The project works perfectly live so I believe that the issue lies with the way I have set up my xampp httpd.conf file. As per instructions found on this site and other sources I have mad the following changes to the httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
DocumentRoot "C:/Users/Me/Documents/Github"
<Directory "C:/Users/Me/Documents/Github">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
When I go to localhost and click on the project I am just getting a 404 error. I've been struggling with this for a couple of days now and don't know how to proceed. Can you see an issue with the way I've set up the httpd.conf file? Thanks for the help!
EDIT: Added the rewrite rules being used.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
SetEnv ENVIRONMENT development
This could be a wild guess but when I look at my Xampp apache config it has
..
allow from all
Require all granted
</Directory>

only default permalinks working wordpress others become 404 error

My problem is in my wordpress site only default permalinks is working.. When I change permalinks all pages become not found.. only home page is showing.
When I change permalinks to postname .htaccess content change to
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And for default it is
# BEGIN WordPress
# END WordPress
Also tried to get the status of mod_rewrite using this
in_array( 'mod_rewrite', apache_get_modules())
It returns 1 and mod_rewrite is enabled on my server and also checked using phpinfo(). mod_rewrite module is loaded.. I have gone through all the documents available in internet.. Please help me to solve this problem.. My hosting server is godaddy..
In case you are on Ubuntu, edit the file /etc/apache2/apache2.conf (here we have an example of /var/www):
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and change it to:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
also check Apache configuration file for your website /etc/apache2/sites-available/your_site.conf:
<Directory /var/www/your_site_path/>
AllowOverride None
</Directory>
and change it to:
<Directory /var/www/your_site_path/>
AllowOverride All
</Directory>
You need to do sudo a2enmod rewrite to enable module rewrite
then,
sudo service apache2 restart
I hope this helps you!
It could be a broken rewrite_rules field in your database.
I installed "Yoast SEO" into a live site and that broke it completely. I disabled the plugin but it didn't go back to working. Only default permalinks would work.
Like everyone else I tried the usual things - checking .htaccess, making sure that mod_rewrite was working on the server, saving the permalinks settings again, but nothing was working. The homepage would load, and wp-admin pages would load, but everything else was just loading the "Latest Posts" default page.
In the end it turned out to be something wrong with the rewrite_rules field of wp_options in the database.
I had three versions of the site (local, staging and production), and all were from one SVN base, so I knew it was not a file issue. But only the local development version was working.
I replaced the contents of the rewrite_rules field of the broken live site with the working one from my local development site, and it worked.
What's really weird is that deleting the rewrite_rules field and having WordPress rebuild it did not fix the problem. Only replacing with the contents of a previously working version of the site did the trick.
I'm still puzzled by this, and will edit this reply if I find out anything further about the problem.
I had the exact same issue and fixed it by running
sudo a2enmod rewrite
Then restarted apache. Apparently the issue is caused by mod_rewrite potentially not working properly on ubuntu.
I found the solution here
suffered from the same issue. Having site on SSL had to change NOT the 000-default.conf but the respective SSL conf file. Adding
after DocumentRoot /var/www/html
the following
<Directory "/var/www/html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
and then restarting apache2 saved my site.... nothing else worked. The issue was Wordpress SSL and SEO plugins messing up config files.
I had this issue in Wordpress installed on CentOS7 and the solution was to edit httpd.conf file with this command:
sudo vi /etc/httpd/conf/httpd.conf
And replace
<Directory "/var/www/wordpress">
Options Indexes FollowSymLinks
AllowOverride none
Require all granted
</Directory>
with
<Directory "/var/www/wordpress">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
then restart Apache:
sudo systemctl restart httpd.service
Not sure this is too late. i faced the same issue and solved by changing
AllowOverride None
to
AllowOverride All
in /etc/apache2/sites-enabled/000-deafult.conf file. hope this would help.
I faced the same challenge after setting up WordPress on Ubuntu 22 and configuring an SSL certificate for the site.
This is how I was able to resolve it.
Open the apache config file for editing (using nano in this case)
sudo nano /etc/apache2/apache2.conf
Change the following line:
<Directory "/var/www">
Options Indexes FollowSymLinks
AllowOverride none
Require all granted
</Directory>
to:
<Directory "/var/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Open the default SSL config file for editing
sudo nano /etc/apache2/sites-available/default-ssl.conf
Add the following code:
<Directory "/var/www/html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Restart Apache
sudo service apache2 restart
You should now be able to change the site permalink structure without seeing the 404 page not found error.

Categories