.htaccess Rules for Site Verification

toolbox

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…


Discover more from LonMakes

Subscribe now to keep reading and get access to the full archive.

Continue reading

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