简体   繁体   中英

how to find redirect source through htaccess in php?

I have a site with lots of links that redirect to a small set of links.

I used the htaccess redirect 301 to redirect a user going to www.example.com/something/something_else/ , to www.example.com/my/collective/url/index.php where something and something_else are not actual folders but just keywords. Is there a way in index.php to know which url it was redirected from?

I tried $_SERVER['HTTP_REFERER'] but it gave me nothing.

EDIT: the rewrite rules I used are as follows:

RewriteRule ^something/something_else/(.*)$ /my/collective/url/$1 [R=301,L,NE,P]

UPDATE: I eventually added a php script for the rewrite, in order to get the HTTP_REFERER. Seems there is no way to properly get it, since after redirect the HTTP_REFERER turns to the redirected url or disappears entirely. Would still be happy to get an answer though if there is a way.

You can use $_SERVER['REQUEST_URI'] this will not be affected by a RewriteRule, but will not do any good no a pure redirect.

Instead of using a line like so:

RewriteRule ^.*$ index.php [R=301,L]

You could remove the R=301 part to not change the page location viewed by the browser, that way, the user thinks he really landed on your page using the /something/something_else link. This is also perfect for SEO... Just look out to not create too many links pointing to the same content...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM