Home .htaccess rewriting URLs that don't exist
Reply: 0

.htaccess rewriting URLs that don't exist

user1195 Published in March 21, 2018, 8:15 pm

Currently, I'm working with some guys that love short URLs for marketing purposes when posting to social media.

They have https://www.example.com/folder/subfolder

For their marketing, they would like https://www.example.com/mysuperbuzzword which would point to the first URL but in the browser, you would still see the shorter URL.

My first thought was "I'll just add a rewrite rule in the .htaccess"

Something like Redirect 301 /mysuperbuzzword /folder/subfolder/ which would work but then the URL changes.

I did some reading and discovered the [P] flag. Then I tried this:

RewriteCond %{REQUEST_URI} ^/vanityurl RewriteRule ^(.*)$ /folder/subfolder [P]

The issue I have now is that because /vanityurl doesn't exist, instead of rewriting, I just get a 404 error.

I've been testing my rule using a .htaccess rule checking tool and the URL it spits out looks correct, but again, I just get a 404.

Also, if you use the flag [PT] the resource is found but the URL is changed in the address bar.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.242441 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO