0
votes

I've just migrated a Wordpress from live to localhost and can't get to work permalinks.

I'm pretty new on this and I'm using Xampp for MacOS. I want to use URLs like localhost/side/about and when I set those on wp-admin it prompts a 404. I've been digging around but the thing is that when I put the .htaccess inside the root folder of the site it just makes .php files downloadable, so I deleted it (have a copy ofc) and it worked great. Now I just need permalinks to be SEO friendly.

The .htaccess file downloaded from the live site looks like this:

# 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
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming 
language.
<IfModule mime_module>
AddType application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

My local site is located on /htdocs/side

Thanks

1
Go to Settings > Permalinks and click on Save a couple of times to make sure WordPress rebuilds its permalink cache. - cabrerahector
That doesn't work for me. Wordpress says: You should update your .htaccess now. Thing is I do not have a .htaccess. - ajmnz
Seems like WordPress is unable to update your .htaccess file. Check your permissions, as Tauseef said below. - cabrerahector

1 Answers

0
votes

There can be many reasons for this but majority of the times it's either file permissions or Apache mod_rewrite module. Here is how you can fix this for these two reasons:

File Permissions Issue: You will need to give your Wordpress folder some permissions, for that use the following commands in terminal, then check for override rules in /etc/apache2/httpd.conf and then restart your Apache server and check if it works

sudo chown _www:_www /YOUR_WORDPRESS_DIRECTORY_ADDRESS
sudo chmod 0775 /YOUR_WORDPRESS_DIRECTORY_ADDRESS
sudo dseditgroup -o edit -a username -t user _www

In your case /YOUR_WORDPRESS_DIRECTORY_ADDRESS will be /htdocs/side and also change username to your username.

After this ensure that AllowOverride is set to All for your web root directory in /etc/apache2/httpd.conf.

Apache mod_rewrite Issue: To check that mod_rewrite module is enabled, look at /etc/apache2/httpd.conf and ensure that this line:

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

is uncommented, if not then uncomment this and restart the Apache server.

Also put this in your .htaccess file:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteRule ^(.*)/$ /$1 [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Hope this helps!!!