Home Is it possible to get the original URL after a 302 .htaccess RedirectMatch?
Reply: 0

Is it possible to get the original URL after a 302 .htaccess RedirectMatch?

user1048
1#
user1048 Published in July 16, 2018, 2:45 am

Hello guys. I started coding my own "URL shortener". The basic idea is you use example.com/12345 to redirect to another URL. This "matching" is done by using .htaccess to redirect stuff towards a script that does (irrelevant for us now) stuff.

My .htaccess currently looks like this:

RedirectMatch 302 ^/\w{5}$ /redir.php

The redirect matches any string of exactly 5 and sends it toward my PHP script where the actual redirection to the expanded URL take place. The only problem is that I was unable to find a proper way of getting the original URL, the matched one into a variable.

As a sidenote the whole thing happens on a VPS set up by me with minimal knowledge, so if this problem can originate from a missing config ($_SERVER['HTTP_REFERER'] doesn't work), then expect my configs to not be 100% correct and by standards.

EDIT: changed from RedirectMatch to RewriteRule, still doesn't work.

RewriteRule ^\w{5}$ /redir.php [R,L]
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO