I have just migrated my WordPress site from a Windows to a Linux server. Everything seems to work except the posts with the permalinks set to /%postname%/. I assumed this was mod_overwrite issue.
I have changed the httpconf file from AllowOverride None to AllowOverride All
And then reset the server just to make sure it took effect.
My .htaccess looks like this:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
I'm running Apache 2.2 on CentOS5 on a dedicated server.
To add: all the pages are working except the posts with these custom permalinks.
I have set permission to 666 for the .htaccess
The same happened with me too. It turned out that .htaccess was not the issue for me. The issue was in server configuration file.
For AWS EC2 server:
Step 1: Edit configuration file
sudo nano /etc/httpd/conf/httpd.conf
Edit this file and change
<Directory /var/www/html/wordpress/>
AllowOverride None
</Directory>
to
<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>
Note that here, /var/www/html/wordpress/ is path to the root folder where WordPress project was hosted.
Step 2: Restart server
Please don't forget to restart your server after you do the changes to the .conf file.
sudo service httpd restart
For Ubuntu server:
Step 1: Edit configuration file
sudo gedit /etc/apache2/apache2.conf
Edit this file and change
<Directory /var/www/html/wordpress/>
AllowOverride None
</Directory>
to
<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>
Note that here, /var/www/html/wordpress/ is path to the root folder where WordPress project was hosted.
Step 2: Restart server
Please don't forget to restart your server after you do the changes to the .conf file.
sudo service apache2 restart
Keep AllowOverride none.
Remove the .htaccess file and any trace of that messy set of rewrite rules and just add this in virtualhost:
FallbackResource /index.php
Neither mod_rewrite, neither .htaccess are needed.
By adding per-dir configurations you are basically complicating your life. Everything will be much harder to do, for what? to have dynamic changes by changing a file? .htaccess is meant for non-admin users who need to modify directory configurations.
Since you are the admin, configure everything possible in Virtualhost instead.
Giving rw permissions to everyone to files is definetly not the way to go either. httpd does not need write access to anything.
Related
I am new to Wordpress but tried all documentation and Stack Overflow posts for possible solutions but none of them have worked so far.
I have verified that mod rewrite is enabled and working as expected. Followed all steps mentioned here. https://wordpress.stackexchange.com/questions/105795/remove-index-php-from-permalinks
Also restarted Apache couple of times but still getting 404 errors when I remove index.php path from Permalink Settings.
Renamed the wordpress directory to blog to access the site at www.xyz.com/blog. Now the requirement is to access any blog posts with
www.xyz.com/blog/2018/02/09/my-wp-post without index.php in the URLs.
We don't have any other CMS content other than WP for the blog site.
Permalink settings(Custom Structure):
/index.php/%year%/%monthnum%/%day%/%postname%/
.htaccess file contents:
BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
I spent ton of time trying many different approaches answered here or elsewhere but none of them fixed my issue.
This is what I did and it has fixed my issue.
Change permalink settings to remove index.php
Update/Save .htaccess content that's at the root of the WP installation if it's not allowed to be updated automatically when we change permalink settings in WP admin panel.
This is the important step since not many Q & A mentioned this in detail, other than wordpress documentation here. Specifically check AllowOverride settings and change it to All, Apache httpd.conf will not load the .htaccess contents without this change. Of course mod_rewrite must be enabled in the server if it's not already done. In our case it's enabled by default, so didn't have to mess with this step.
Also make sure FollowSymLinks option enabled as mentioned in the WP documentation.
Last but not least, make sure you restart the Apache service/server for the changes to take effect.
Entry in httpd.conf file:
<Directory "/var/www/html/blog">
Options FollowSymLinks
AllowOverride All
Assuming Ubuntu 16.04 & Apache2
1) Activate mod_rewrite. It's available but not enabled with a clean Apache 2 installation.
sudo a2enmod rewrite
2) Restart Apache
sudo systemctl restart apache2.service
3) Setup .htaccess
(Note: Apache reccomends using a server configuration file over inserting rules into .htaccess, however, for this example, inserting rules into .htaccess is sufficient because of the negligible performance hit.)
sudo nano /etc/apache2/sites-available/000-default.conf
Insert the following in 000-default.conf
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
4) Restart Apache
Repeat step 2
5) Create .htaccess in the web root.
touch /var/www/html/.htaccess
Insert the following into .htaccess
RewriteEngine On
6 Configure the URL Rewrite (Note: Assuming index.php)
sudo nano /var/www/html/.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
mod_rewrite is a useful Apache module that can be used effectively to ensure human-readable URLs and good SEO results. If you'd like to learn more about mod_rewrite, take a look at Apache's mod_rewrite Introduction and Apache's official documentation for mod_rewrite.
In a nutshell, as #Cnu as mentionned, the problem very few resources on the internet touch on is the fact that your apache configuration must contain an AllowOverride FileInfo directive for wordpress rewrites to work without /index.php/.
Since Apache 2.4, AllowOverride default setting is "None", which is often a roadblock in making "pretty urls" work (in this case ditching the index.php). As #cnu mentionned, you should read carefully this resource : https://wordpress.org/support/article/using-permalinks/.
Make sure to have mod_rewrite enabled
-> (to be sure create an info.php you will remove later containing the line <?php phpinfo();?>) at the root of your blog and call https://domainofyourb.log/info.php)
Make sure your .htaccess is writable by wordpress. (permission and ownership should be allowing your webserver (often with the username "apache") to edit the file.
Change your wordpress permalinks settings, and check that .htaccess file is correctly written.
Check that your apache configuration (etc/httpd/conf/httpd.conf in some linux distros) contains the directive AllowOverride FileInfo within your blog's <Directory></Directory> section
Options directive to FollowSymLinks should be the default, but if Options directive is mentionned, add FollowSymLinks for good measure.
when all that is done, don't forget to restart your Apache server. (sudo service httpd restart in my case, ymmv).
P.S : wrote this answer because I can't comment (don't have rep) on cnu's answer, and wanted to correct 1. allowoverride doesn't need to be set to ALL, it can be set to simply "FileInfo", 2. update the link to wordpress doc, and 3. provide background on the change in apache 2.4 that causes this issue.
Go to admin page, Dashboard -> Settings -> Permalink Settings -> Custom Structure, select /%postname%/ or, /%year%/%monthnum%/%day%/%postname%/ up to you.
I have Wordpress 4.1 application on DigitalOcean.
After installation I found that any other link besides root/home link don't work.
I looked into similair questions and tried:
1) Change permalinks to default settings.
Now links partialy work. I mean they are ugly :http://104.131.95.146/?post_type=product instead of http://104.131.95.146/products
As suggested I did some troubleshooting from this link :
Pretty permalinks are available under:
Apache web server with the mod_rewrite module
But my server is Apache and I checked if mod_rewrite is aviable with:
apache2ctl -M | grep rewrite
got this message :
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
rewrite_module (shared)
Tried to restart apache and my droplet but still the same problem.
My htacces file inside var/www/html/.htaccess
# 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
Any help would be great.
Thanks in advance.
Once again fixed by myself.
I skipped important part of Wordpress installation.
What I did:
By default, this is 000-default.conf, but your file might be different if you created another configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
Inside of this file, we want to set up a few things. We should set the ServerName and create a directory section where we allow overrides. This should look something like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ServerName server_domain_name_or_IP
<Directory /var/www/html/>
AllowOverride All
</Directory>
. . .
When you are finished, save and close the file.
Next, we need to enable the rewrite module, which allows you to modify URLs. You can do this by typing:
sudo a2enmod rewrite
After you have made these changes, restart Apache:
sudo service apache2 restart
I updated the permalink structure to /%postname%/ and this updated my .htaccess with:
# 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
But I still get 404 errors on the pages. Are there any other settings that I need to change?
Edit: if it helps the apache log seems to be looking directly in the permalinked folder. I.e.:
[Wed Oct 16 11:12:32 2013] [error] [client xx.xx.xx.xxx] File does not exist: /var/www/exampledomain/news, referer: http://exampledomain.com/
For other people landing on this page -
Another issue could be (If you are using Apache as your web server) is your httpd.conf or your sites-available/sitename.conf file needs editing.
Your web directory will need to allow the .htaccess file to override it's settings.
look for your web dir in the file - it will be in the bulk of the conf file or segregated into a VirtualHost section.
<Directory /path/to/site>
#add the following setting to allow .htaccess in your web dir to work
AllowOverride FileInfo
#other settings ---
</Directory>
This will allow you to set up WordPress URLs however you want, within WordPress.
***Edited - Thank You nietonfir For update. Use the least amount of privilege at first. If this doesn't work then replace AllowOverride FileInfo with AllowOverride All
There can be multiple things preventing the rewrite rule from working. My ubuntu server needed 3 things changed to get permalinks working.
In newer versions of apache2, you need to enable the module:
sudo a2enmod rewrite
sudo service apache2 restart
You may also need to modify the apache2.conf file.
sudo nano /etc/apache2/apache2.conf
Change your web directory override rule to AllowOverride All.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After that, restart the service again.
The .htaccess file in the WordPress install directory needs to be owned or readable/modifiable by the webserver.
This can be accomplished by changing owner to www-data (usually the webserver user), or changing permissions.
sudo chown www-data /var/www/wordpress-install/.htaccess
OR
sudo chmod 664 /var/www/wordpress-install/.htaccess
Login to your Wordpress admin backend and save the permalink settings, and they should hopefully be working.
This is now solved. I hadn't enabled mod_rewrite. So I did this:
$ sudo a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart
$ service apache2 restart
* Restarting web server apache2
You would want to tell apache to follow your .htaccess file. You can do this by editing the apache.conf file
$sudo nano /etc/apache2/apache.conf
Scroll down to the line
By default it will be:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
change the value of AllowOverride to All so now it becomes:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Press ctrl+x and press y to save the configuration file. In order to make this changes to server first enable the mod_rewrite by.
$ sudo a2enmod rewrite
And then restart the server
$ sudo service apache2 restart
Done!
Source: https://www.wst.space/riddling-with-wordpress-permalink-setup-issues/
use below .htaccess code, just put your project name (which is in www directory) in below code
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project_name/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /project_name/index.php [L]
</IfModule>
# END WordPress
Thanks
I was facing with the same problem and had one more thing to look for.
Here is what you need to do for wordpress permalinks work properly:
Make sure you have the proper permission modes for files and folders in your wordpress directory:
sudo find . -type f -exec chmod 644 {} +
sudo find . -type d -exec chmod 755 {} +
For permalink structure make sure mode_rewrite is enabled in apache:
sudo a2enmod rewrite
sudo service apache2 restart
One more thing to check if this describes your problem:
htaccess and mod_rewrite are set up correctly
404 error on some permalinks but not others
Ensure that there are no existing .php files or directories in the same folder as your Wordpress install with names matching a Wordpress permalink.
For example, if you have the following Wordpress page permalinks:
example.com/name_one/
example.com/name_two/
and the directory containing your Wordpress install includes the following file:
name_one.php
then this will be the result:
http://example.com/name_two/ – this permalink will work
http://example.com/name_one/ – this permalink will NOT work
More importantly, the second URL will give a 404 instead of running name_one.php, meaning this problem is hard to diagnose, as it can give the same symptoms as an incorrectly written .htaccess file.
If you are setting up a new or cloned site on ubuntu, remember to symlink the site configuration file e.g. /etc/apache2/sites-available/your-file.conf to the /etc/apache2/sites-enabled folder so apache loads it.
Just run: sudo a2ensite your-file.conf, then sudo service apache2 reload.
sudo a2dissite your-file.conf to remove symlink i.e. disable config.
Users of WAMP (Windows): Some versions of WAMP (all versions?) do not enable mod_rewrite or permit following SymLinks by default. To enable the required functionality navigate to the apache/conf/httpd.conf file, open with a text editor and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (i.e., delete the hash/pound sign at the front of the line). Then further down in the same file there is a section that starts with the line "Options FollowSymlinks". Change the second line in that section from "AllowOverride none" to AllowOverride all. Save edited httpd.conf and restart all WAMP modules. Your permalinks should now work.
For more details, Fixing Permalink Problems
Yet another possibility: I just updated my macOS which always screws up the Apache config file. Among other things, I also had to re-enable the mod_rewrite module. Find the line that says,
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
And remove the hash so it says,
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
If you are using Apache, double check no errors in Directory in VirtualHost, Apache wont warn you if you input an incorrect directory:
<Directory /var/www/html/site/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /var/www/html/site/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
The clean URL test failed. It was working correctly on my local computer, when I uploaded it to server I got this message and I could not enable the clean url. What should I do to enable it? I have uploaded the htaccess also.
There are a number of requirements you'll need to confirm are met on the server. After confirming Apache is allowing your local .htaccess configuration override (as per Ayesh's comment) I'd start by checking info.php to see if mod_rewrite is loaded.
Make sure you remove info.php when you're done checking as you should not have this on a production server.
have a look at Configure clean URLs, suppose you are using apache2
enabled mod-rewrite in apache
sudo a2enmod rewrite
vi /etc/apache2/sites-enabled/000-default, change AllowOverride from None to All
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
vi httpd.conf, add this
<Directory /var/www/>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
2. restart apache
sudo service apache2 restart
If your entire site is password protected (via cpanel/.htaccess) Then the test will not pass. This may not be the solution but is worth checking.
I disabled password protection by commenting out the following lines in my .htaccess file.
AuthType Basic
AuthName "public_html"
AuthUserFile "/home/********/.htpasswds/public_html/passwd"
require valid-user
Run the test again, if it passes, tick the box then be sure to uncomment the previously commented lines.
I've been searching for hours but haven't found anything that seems to be able to solves this issue.
Here's the scenario:
I'm making a wp theme based on the "Twenty Eleven" theme. Everything went fine til I decided to change the urls to permalinks. The only page being displayed is the static page that I have defined earlier.
I have set up the htacces file. In fact, WP did it automatically. Everything works if I switch back to the default setting, but, for SEO, I would rather use the permalinks option.
Here is my htaccess file (it is on my WP installation folder):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mysite/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mysite/index.php [L]
</IfModule>
# END WordPress
I have seen this post wordpress .htaccess with permalinks but nothing there could help me. Any help would be very nice.
UPDATE : Things I have tried already:
Delete pages and create again.
Access the permalink field on wp_options (db) and setting the value to blank and set the permalink option in the admin again.
I´m running it on windows 7 through an apache2 installation of Zend Server.
I thought it was a problem related to my localhost environment, so I put the site online. No luck at all. I'm assuming that wordpress can´t change permalinks to a more friendly url type when you set a static front page. What a shame.
For those using apache. You will need to
Ensure you have .htaccess in root path of the site you are hosting. Example /var/www
Update the /etc/apache2/sites-available/default
From
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
To
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Hope this helps someone
If editing apache2's default configuration and Wordpress' .htaccess files don't help the reason could simply be that apache2's rewrite module is not enabled. This is usually the case for those who install apache2 themselves. Wordpress needs apache2's rewrite module enabled to support permalink edits. If, like me, you'd rather not edit conf files by hand, apache2's rewrite module can be enabled by running these commands as root (I'm using Ubuntu 18.04, so these commands might be different in distros that aren't based on Ubuntu or Debian):
a2enmod rewrite
and restart the apache2 service by running:
systemctl restart apache2
or
service apache2 restart
If you're running Ubuntu 18.04, you can check out all available apache2 modules under /etc/apache2/mods-available and see what modules are enabled by listing the files under /etc/apache2/mods-enabled.
I don't know if you have found the solution to it, but I solved this problem by simply turning on LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf file.
Also see Permalinks on WordPress (Amazon EC2)
I had the same problem, but the author in the above link suggested to do three things (it worked for me!):
Go to /etc/httpd/conf and edit httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
Change also AllowOverride if it is set to None
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
I you haven’t created it yet, place in the root directory of your wordpress
installation a .htaccess file with the following contents:
# 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
There are two 'Directory' sections in the httpd.conf file.
One is for root folder and another for htdocs folder.
You must edit both fields to make WordPress pages work again.
Hope it helps.
This worked for me like #Skillachie wrote BUT be also sure to include those settings in the 000-default-SSL.conf file if you use SSL!
<Directory /var/www/PATH>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>