0

The URLs of my website are in the form...

www.website.com/index?t=abc123

...where abc123 is a 6 character hex code. How can I use htaccess to redirect all addresses like this to...

www.website.com/abc123

...but still serve the content at the original URL?

So, for instance, typing...

www.website.com/index/php?t=5f33ee

...would redirect to...

www.website.com/5f33ee

...but would serve the content from...

www.website.com/index.php?t=5f33ee

...without the user being redirected.

So far, my .htaccess looks like this. The first bit, I understand, redirects all not https traffic to https. The second RewriteRule seems to work to serve the content from the short url.

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.website\.com$ [NC]
RewriteRule ^(.*)$ https://www.website.com/$1 [R=301]
RewriteRule ^([0-9a-f]{6})$ index.php?t=$1 [L]
MrMills
  • 151
  • 11
  • This is so common, you will find thousands of examples online. See [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – IMSoP Sep 23 '21 at 14:27

1 Answers1

0

Solved with these rules.

RewriteCond %{QUERY_STRING} !x
RewriteCond %{QUERY_STRING} t=([0-9a-f]{6})
RewriteRule ^/?index\.php$ /%1? [R=301,L]
RewriteRule ^/?([0-9a-f]{6})$ /index.php?x&t=$1 [QSA,L]
MrMills
  • 151
  • 11