How to Mask a URL Redirect with .htaccess

H

Did you install WordPress in a subdirectory because you wanted total control of your website’s front page but now you’re building pages off that front page and you don’t want to go through the hassle of manually styling and managing all of them? Me too. Fortunately, you can still use WordPress to build those pages. And as for displaying them as if they were separate from the WP subdirectory, there’s an .htaccess answer for that as well.

All you need to do is edit the .htaccess file in the DocumentRoot of your website and add a couple lines.

In this example, I’m redirecting the url danielverastiqui.com/vinestead to danielverastiqui.com/blog/vinestead.

RewriteEngine on
RewriteRule ^vinestead/?$ /blog/vinestead/

Just replace “vinestead” and “/blog/vinestead/” with whatever you want to redirect.

And that’s it. Now, when a user clicks on danielverastiqui.com/vinestead, they will be quietly redirected to danielverastiqui.com/blog/vinestead, all without the URL changing. As long as you don’t use relative links for navs and sidebar items, the user should be able to navigate away when they’re done reading.

But Daniel, how will this affect SEO?!

I don’t know. Why are you asking me? The only thing I know about SEO is that the location of the page is important. Maybe. I remember when I was setting up Swifttype at work, things weren’t working because I wasn’t generating the right canonical references for each page, something I didn’t understand then and still don’t understand now.

I’m pretty sure it has something to do with the URL, which in this case is danielverastiqui.com/vinestead, but when the page is generated by WordPress, it will use the “real” URL, as seen in the source:

<link rel="canonical" href="https://danielverastiqui.com/blog/vinestead/" />
<link rel='shortlink' href='https://danielverastiqui.com/blog/?p=1677' />

So, maybe Google won’t like that, but Google can go jump in a lake. What matters is that your website looks the way you want it, and I’d like to see Google, Bing, or the person or persons unknown at DuckDuckGo do anything about it.

About the author

Daniel Verastiqui

Daniel Verastiqui is a Science Fiction author from Austin, Texas. His novels explore relationships and identity in the context of ubiquitous technology, pervasive violence, and frequent nudity. His most recent book, Brigham Plaza, is now available in print and digital formats on Amazon.

Add comment

Leave a Reply

By Daniel Verastiqui

You are cordially invited to...

DINNER, DRINKS, & MAYHEM

Topics

The Vinestead Universe

%d bloggers like this: