I recently had the frustrating experience that a new WordPress staging site that I installed on a Google Cloud Instance was all of a sudden giving 404’s on all my interior pages. I realized this was due to the site not generating “pretty permalinks”. This is the option under settings in which you can have a URL such as http://mysite.com/example rather than have to use http://mysite.com/?p=123
Before one can figure out how to to fix a problem, you first have to figure out what is causing the problem.
For most issues in WordPress, my first point in the debugging process was to deactivate all my plugins, revert to the default theme, and try the process again. When this didn’t work, I knew it was an issue with the .htaccess file.
Is Your .htaccess file working?
The .htaccess acts as a gatekeeper on Apache servers, doing all manner of things including redirects, setting up permalinks and so on. While I’m unlikely to touch the file on a day to day basis, a plugin might corrupt it without my knowing.
Other times it’s possible that one might delete the file completely by accident or make changes to it that break your permalinks.
Reset Your Permalinks
Normally this means that somehow your .htaccess file has gotten corrupted somehow, and just needs to be reset. To do that one would normally just use the usual technique of turning the permalinks off and back on in the wp-admin>settings>permalink page. Next, if your standard permalink structure is set to Day and name for instance, change it to Numeric and click the Save Changes button at the bottom of the screen. Don’t rush to refresh your site yet, there is one more step. Next, select your original permalink structure (i.e. Day and name in our case) and hit the Save Changes button once more. Now you can reload your site and check your posts/pages.
Is the .htaccess file writable?
When this still isn’t working, I need to confirm that the .htaccess file is writable by the server. Bring up the .htaccess file via ftp or ssh. Change the permalinks settings and see if anything in the file has changed. If it hasn’t, check to see if the file permissions are good. According to the codex, 644 is normally required and recommended for .htaccess files.
If you’ve modified the permissions, and running the settings reset hasn’t resulted in any changes to the file, go ahead and TEMPORARILY set the permissions to 777.
If you are now able to write to the file, then you know there’s a permissions issue between the user that controls your WP install, and the files it’s supposed to be able to touch.
In my case it was fine, I saw changes occuring to the file, but there wasn’t a change in the front end permalinks working. This indicated to me that the .htaccess file just wasn’t being used by the server. A real rudimentary way to test this is to put some bad code at the top of the file.
Testing whether your .htaccess file is being used
The simplest way to test if apache uses your .htaccess file, or if it otherwise ignores it, is to intentionally break it.
Edit the .htaccess file, so the first line reads ‘Test.’:
Test: I'M INSERTING PLAIN TEXT TO BRING THE SITE DOWN, WHICH WILL RESULTS IN A 500 ERROR
# Use PHP56 Single php.ini as default
AddHandler application/x-httpd-php56s .php
# BEGIN WordPress
AddHandler application/x-httpd-php70 .php
<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 WordPressNow, if you refresh the page in your browser, you should see an error page like this:

If you got this screen, that’s a good sign. That means Apache is parsing your .htaccess file correctly. So when I didn’t get a broken 500 page error, I knew that the .htaccess file was just getting ignored all together.
How to make your server respect your .htaccess file
First, let’s confirm that the apache mod_rewrite module is enabled.
- Create a new php file in your root folder of your WAMP server. Enter the following
phpinfo(); - Access this file from your browser.
- Ctrl F to open a search. Search for ‘mod_rewrite’. If it is enabled you see it as ‘Loaded Modules’
- If it’s not, then:
Enable mod_rewrite in Apache
There are a number of ways to enable mod_rewrite, in case it’s not yet enabled on your setup. See this Stack Overflow thread for various ways this may be done on different setups: How to enable mod_rewrite for Apache 2.2.
If you are still with me on this journey, the next one is going to be the least familiar and most technical of the steps. Don’t be intimidated but you’re going to need to roll up your sleeves and get into the command line via the browser based SSH built into your Google Cloud Platform Instance.

Step 1) Make sure you have enabled mod_rewrite in apache. This can be done by going through Compute Engine>VM Instances > identify the correct instance and to the far right on the line will be SSH. Click it and it will take you securely inside a command line interface. Run this command:
$: a2enmod rewriteEnable Apache AllowOverride
2) Check your virtualhost configuration in /etc/apache2/apache2.conf and make sure that it is configured with AllowOverride All instead of the default AllowOverride None for your web root directory. This tells apache it is ok for settings in .htaccess files to override settings. Use this command to modify the file.
sudo nano /etc/apache2/apache2.confOnce you're in there, find the right spot and change it.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride ALL <----(edit from none)
Require all granted
</Directory>After you’ve made that change, make sure to restart the server:
sudo service apache2 restartNow, your .htaccessshould work. You can also make this change inside a virtual host, which would normally be preferable, but that depends on the way Apache is set up.



Finally I found you dear. After 3 days of trying to figure out the catch. I hope this one is going to work definitely.
I’m so glad this is able to help you. It drove me quite crazy myself for quite a few days.
Man you are a freakin’ life saver! I’ve been developing sites for 7 years but I am very, very new to Google Cloud…
I spent hours digging through this until I came across your post.
Thank you for sharing this!
Many thanks for your post, it is the only one that I found about this, however, I am having problems to run the command “$: a2enmod rewrite”
Could you help me with this?
Initially, this is what I found:
info@wordpress-1-vm:~$
but when I write your command and press enter I get this:
info@wordpress-1-vm:~$ a2enmod rewrite
-bash: a2enmod: command not found
Many thanks for your help!!
Hi Hector,
You’re probably aware of this, but just to make sure, you’re not actually typing the “$: ” in your commands, right? That’s just the stand in representing that you should run the command (without the $) as a regular user, as opposed to running it as root.
I had the same problem and error message as Hector…and I only used “a2enmod rewrite”. Any ideas?
I was so happy that I could have fixed it with this article, but in my case – it didn’t.
Thanks to the article, I could check that my re-write module is enabled, and I could have confirmed that my .htaccess file is ignored. I have no idea what’s next :(
I am running a clean wordpress instance on google cloud (instance is a google cloud marketplace instance wordpress already installed) ; totally fresh vm (at least 5 times).
Any idea how I can fix it? Many thanks in advance
Should I keep digging or just to
Hi Ark,
Did you follow through with enabling Apache AllowOverride? The last (and only time) that I installed a fresh WP install on Google Cloud this was the final step I had to go through.
This is so awesome. Thank you for saving me what looks like it took other readers days to figure out.
Thank you! Crikey, I had tried everything that I could think of doing to get my desired permalink structure to work, and got absolutely no where except the awful 404 page. Your solution worked!
You’re so welcome Liam. Knowing that my own hard learned lessons can be helpful in getting my fellow developers to a place of peace makes writing these tutorials worthwhile. Lord knows, it’s certainly not to impress my potential clients with all the jargon and geek speak :D
Attempting in ssh:
a2enmod rewrite
returned..
-bash: a2enmod: command not found
.. in every directory i attempted.
Does this also apply to appengine projects? I cant seem to reroute permalinks.
For me showed theres no
/apache2/ directory in
/etc/apache2/apache2.conf
in ssh root.
Sorry Charles, I am not familiar with the App Engine side of Google Cloud. It’s a really dense platform with so many technical possibilities.
thanks for the great tutorial, still it did not work for me, I’ve followed every single step but .htaccess is still getting ignored.
I’m not using WordPress, it’s a Expression Engine installation, but still the root proble is the same, google computer engine ignoring .htaccess.
I’ve posted the question here if anyone feels like contributing! :)
https://expressionengine.stackexchange.com/questions/41176/removing-index-php-from-urls-on-google-cloud-computer-engine
Alas, I’m very ignorant as to the logic of Expression Engine, so I’m not so qualified to answer. sorry.
sure, I understand, although the problem at the end of the day is that the .htaccess is gettign completely ignored. I tried breaking it to get a 500 as you suggested but it did not work anyway. still, thanks for the great tutorial, it was really easy to follow!
Your are monster, Fantastic article bro, keep the good work going, solved my problem of one week.
Thank you! 1000 times over!
I’ve been stuck on /plain permalinks for a week now. This was the only tutorial that was clear, well structured and most importantly, worked!
I just skipped to enable mode_rewrite in Apache. Step 1 and 2.
Now expecting much when i went back to my browser, but then…. wow!
Wow! Thanks a bunch for this fix. I’m purely designer and I dread doing anything related to coding. But I thought of giving this a shot, since you explained it so well. In just a few steps, I was able to get the issue solved. Thanks again!!
While this is an old tutorial, it surely solved my problem. Thanks very much.
Fred
Well, I cant yet. I can access my wp-admin, but the pages not.
“Not Found
The requested URL /pt/home/ was not found on this server.”
Have you idea?
are you able to navigate around your backend, to the permalinks section? Did you follow all the instructions step by step?
pls help with clear it doesnot work for me
At what point does it fail? You’ll need to provide more details for me to be able to offer anything of value.
Oh god, finally after lot of googling I found what I wanted. This post is awesome. Thank you. Keep sharing.
Where have you been all my life???
What a legend, thank you bro..
True lifesaver!
Thank you for sharing this piece of knowledge.
I am very new to GCloud and this really helped me after moving a WP site to GCloud. :)
You are the real life saver…solved my problem . Thank you very much.
Gray hats off, & God Bless You,
I am not a Developer, but you have Written in so simple language, even non-developer person would also understand, it took a little long for me to figure out since I am not that smart, but in the end, you solved my problem, once again thank you so much.& God Bless you
There is one more post which is to the point: https://seomileage.com/fix-wordpress-permalinks-on-google-cloud/
Thank you so much for this. You really make an impact :)
thanks it works
Thank you .. now permalinks are working.. !
Thanks dude ..
Enable mod_rewrite in Apache worked for me. THANK YOU VERY MUCH! Really a life saver :)
I was tired finding solutions :(
Hi
Once apache config file is updated how to save it on command line
Thank you so much. I fixed my trouble
It not work for me. index.php will not go away. If I remove it in permalinks then requested url not found
Thanks for your post. Very useful information.
Thank you so much, that helped me…
confirm that your WordPress Address & site URL are correct and both in the format
http://www.domain.com or https://www.domain.com
Once I changed this it totally worked!!
Thanks for the post! Are any of you using HTTPS through a load balancer? This causes problems because most of those load balancers transmit the packets
[client] — https –> [load balancer] — http –> [instance]
Notice the connection between the load balancer and the instance is in http, not https.
Therefore, when the https request reaches the instance, apache returns a redirect, which in turn causes the browser to resend the https request. So this solution has not worked for me.
Any ideas around here?
Same problem here. I cannot get pretty permalinks to work with google cloud and SSL load balancer. It always returns server error 502