.htaccess Rules for Site Verification

toolbox
"Toolbox" by Florian Richter https://www.flickr.com/photos/florianric/7263382550

Here’s two .htaccess Rewrite rules from my toolbox that have made my life simpler, and I figured they could help others as well.

These short tutorials assume:

  • You have ftp access to your site
  • Your site is running Apache
  • Apache has the mod_rewrite.c module enabled (most installations do)
  • You have permission to create and edit a site-level .htaccess file

Let’s Encrypt

.well-known/acme-challenge/long-random-id

Recently, I was asked to post a Let’s Encrypt verification file for a site that was changing hosts.
The old host doesn’t allow access to “hidden” folders. (Files and folders that start with a dot.)
Any attempt to pull up the URL results in 403 Forbidden.

To avoid having the server attempt to access a hidden folder, I just rewrite the incoming URI to something the server CAN access.

Step 1: Create folder for your verification files

I called mine “lets_encrypt.”

Step 2: Upload the verification file to that folder

It’s that file with the gibberish name you got from Let’s Encrypt.

Step 3: Add a rewrite rule to .htaccess

RewriteEngine On
# Let's Encrypt validation server-side rewrite to work around
# hosting limitation about hidden folders.
RewriteRule ^\.well-known/acme-challenge/(.*)$ /letsencrypt/$1 [L]

 

Put this rule towards the top of your .htaccess file before any rewrites for WordPress or caching programs.

Google Property Verification

Many Google services require you to verify your property.

One of the simplest methods is to upload a file, but some modern publishing or hosting environments sometimes have issues serving up a simple file.

And you may not want those HTML files cluttering up your root directory.

An Apache Rewrite rule  can solve this problem.

Step 1: Create a folder for your verification files

I called mine “google_verify”

Step 2: Upload the verification file to that folder

This is the file you get from the “HTML file upload” verification method.

Step 3: Add a rewrite rule to .htaccess

RewriteEngine on
RewriteRule "^/?.*?(google[0123456789abcdef]+\.html).*$" "%{DOCUMENT_ROOT}/google_verify/$1" [L]

Put this rule towards the top of your .htaccess file before any rewrites for WordPress or caching programs.

 

Step 4: Profit!

Now whenever you need to verify a property , you can just drop the  file in the appropriate folder.

Or better yet, hand off that task to someone else who has ftp access…

Leave a comment

Your email address will not be published. Required fields are marked *

Prove you are human by reading this resistor:

0Ω+/- 5%

0
0
1
2
3
4
5
6
7
8
9

0
0
1
2
3
4
5
6
7
8
9

0
0
1
2
3
4
5
6
7
8
9

5
5
10

Prove you are human by reading this resistor:


Click/tap drag the number in the circle of each slider on the left to the matching color band on the resistor.

Can't view resistor colors? Don't worry! Just type your comment and hit submit without moving the sliders. Our moderators will review and approve in a jiffy.

Click Here for a new resistor image.

New to electronics? Click here to learn how to read resistor values.

Or learn to read resistors by playing Mho's Resistance!

We uses cookies to monitor visitor activity on our site. We do not record personally identifiable information without express consent. Read our privacy policy

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close