homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

log redirects

 3:02 pm on Nov 29, 2013 (gmt 0)

i was wondering if there is a way to log 301 redirects issued from htaccess, just by using php, no apache modifications (no htaccess rules, no http.conf modifications, no apache logs)
just plain php code.



 4:49 pm on Nov 29, 2013 (gmt 0)



 9:46 pm on Nov 29, 2013 (gmt 0)

On the other hand: If you take all the pages you're currently redirecting, and instead rewrite them to a php page which does the lookup and issues the 301, it should be fairly trivial to log that activity. Where "fairly trivial" = I have no idea how to do it,* but I'm confident that someone hereabouts does.

* I can follow directions at php dot net, but only if I know where to look in the first place.


 6:44 pm on Nov 30, 2013 (gmt 0)

Pretty simple if you use a PHP script as Lucy suggests.

Either append to your 301 log file like:

file_put_contents('/var/log/httpd/301.log', "\nA message containing pertinent details", FILE_APPEND);

Or insert into your database table.

Then simply issue the correct header:

header('Location: http://www.example.com', true, 301);

 8:56 pm on Nov 30, 2013 (gmt 0)

no apache modifications
rewrite them to a php page
these are mutually exclusive

 9:45 pm on Nov 30, 2013 (gmt 0)

Picky, picky :P But the 301s have to come from somewhere. So if you replace the existing redirects with a rewrite to a different page, it barely counts as a "modification".

That's assuming the redirects originate in htaccess. (OP specifically said they do.) If they are all in-page redirects, it's a whole nother ballgame.

omoutop, do you have access to the config file? If yes, why are you also using htaccess?


 6:49 am on Dec 2, 2013 (gmt 0)

6 months ago we change out site - new design and new urls
so we had around 25000 301 redirects
now we change some urls again and old redirects must be replaced with new ones

we need a way to monitor which 301 rules are still active (user bookmarks, bots, anything) and which ones are no longer apply so as to clear out this 301 list

the php file seems good solution - i can move all 301 rules to a table in database and monitor from there.

i will give it a try


 9:29 am on Dec 2, 2013 (gmt 0)

The day after you remove a no-longer-needed redirect, some major search engine will swing by and request three hundred of your old URLs.



 11:10 am on Dec 2, 2013 (gmt 0)



 12:07 am on Dec 3, 2013 (gmt 0)

I know you mentioned "no apache logs", but I'm curious... are your access logs not available?


 8:36 am on Dec 3, 2013 (gmt 0)

no penders
i have no access to any logs, to no conf files
only access i got is limited ftp


 7:25 pm on Dec 3, 2013 (gmt 0)

No logs AT ALL? Sounds like it's time to go host-shopping.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved