Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter mathiasbynens

    (@mathiasbynens)

    Alrighty then…
    Is it possible to retrieve the full request URI through PHP?
    So, if someone accesses a page, I want to know through which URI. But I need the full URI (not only $_SERVER['REQUEST_URI']!)…
    Thanks in advance.

    Try SERVER_NAME, maybe.

    Thread Starter mathiasbynens

    (@mathiasbynens)

    Ooh, old thread. Now that these forums work with tags, I thought I’d post my solution here as well; maybe this will help others.

    Yeah, skippy, $_SERVER['name'] wouldn’t have worked, as that’s a fixed server variable, which won’t depend on wether you access a page using a no-www address or not. What I was looking for, appeared to be $_SERVER['HTTP_HOST']. Anyway, given this knowledge, I managed to write a PHP script that sends headers that redirect the browser to the www.-less address and tell search engines like Google that the move is permanent, so they can update their indexes. And what’s even better is that there are also mod_rewrite rules available that do the same.

    Firs let me apologize for the length of this post. Here is how I use .htaccess to redirect user agents to where I would like them to go. I allow all commonly known browsers to attend my precious blog and as for the Bad spiders and agents they get a suprise. I would not suggest you go to lemonparty.org under any circumstances – it’s a vulger site.

    RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^MSIE/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Opera/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Icab/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Links/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Netscape/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Multizilla/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Avant\ /Browser/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Safari/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Konqueror/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Elinks/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^w3m/.*

    RewriteRule ^.*$ http://www.mysite.com/

    RewriteCond %{HTTP_USER_AGENT} ^BaiDuSpider/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Crescent/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^CherryPicker/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^CherryPickerSE/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^CherryPickerElite/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^EmailCollector/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^EmailWolf/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^ia_archive/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^ia_archiver/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Mozilla.*NEWT [OR]
    RewriteCond %{HTTP_USER_AGENT} ^[Ww]eb[Bb]andit/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^WebEMailExtrac.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^NICErsPRO/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Telesoft/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^MSFrontPage/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^TV33_Mercator/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^BlackWidow/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]
    RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^DISCo/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^eCatch/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^EirGrabber/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^FlashGet/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^GetRight/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^GrabNet/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Grafula/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^HMView/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^HTTrack/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^InterGET/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^JetCar/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^larbin/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^LeechFTP/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Navroad/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^NearSite/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^NetAnts/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^NetSpider/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^NetZIP/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Octopus/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^PageGrabber/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^pcBrowser/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^RealDownload/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^ReGet/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Siphon/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^SmartDownload/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^SuperBot/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Surfbot/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^tAkeOut/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^VoidEYE/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR]
    RewriteCond %{HTTP_USER_AGENT} ^WebAuto/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^WebCopier/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^WebFetch/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^WebReaper/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^WebSauger/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^WebStripper/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^WebWhacker/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^WebZIP/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Widow/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Zeus [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Microsoft\ URL [OR]
    RewriteCond %{HTTP_USER_AGENT} ^LinkWalker/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^InternetSeeker.com [OR]
    RewriteCond %{HTTP_USER_AGENT} ^S.T.A.L.K.E.R. [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Seeker.lookseek.com [OR]
    RewriteCond %{HTTP_USER_AGENT} ^sitecheck.internetseer.com [OR]
    RewriteCond %{HTTP_USER_AGENT} ^UdmSearch.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Ziggy\ –\ The\ Clown\ From\ Hell!!
    RewriteCond %{HTTP_USER_AGENT} ^Down\ Deamon/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Gulper\ Web\ Bot/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^OmniWeb/.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^SearchExpress/.*

    RewriteRule ^.*$ http://www.lemonparty.org/

    <Limit GET HEAD POST>
    order allow,deny
    allow from all
    </LIMIT>

    I’ll have to start another post to explain how to redirect to other pages and accept query strings.

    Again I apologize for the length of the posts however I wanted to give you all a pretty current example of all the good and bad spiders so you wouldn’t have to spend the time researching them.

    For redirecting to other pages and sites, there are many ways to do this using htaccess. I’ll describe a few and let you read apaches manuals for the rest.

    Starting with redirecting to new pages in a different directory. For this you will need to put the htaccess file in the same directory you want to be redirected. Make sure you do use this method in /.

    RedirectMatch (.*)/oldfile.php
    http://www.mysite.com/newdirectory/newfile.php

    For multiple redirects, should appear on separate lines.

    This changes the directory to where the “new” source files are located.

    Maybe you’d like to redirect the entire directory?

    RedirectMatch (.*)/
    http://www.mysite.com/directory/index.php

    Another way to do this and is cleaner:

    RewriteEngine on
    RewriteBase /~dir/
    RewriteRule ^index\.php$ home.php

    This adds a little backward compatibility and users wont even know the page has been changed.

    or maybe the entire directory?

    Redirect /sourcedir http://www.mysite.com/newdir

    Your source directory should be the same path as it is right after your docroot.

    Alot of times you’ll want to capture the query strings and they are NOT a part of the url. You’ll need to do something like this:


    RewriteCond %{QUERY_STRING} ^cat=([0-9]+)
    RewriteRule /index\.php$ http://www.yoursite.com/your page.html [R=301,L]

    Of course this is sending the request to a 301 page but you can send it to wherever you like.
    This will ‘copy’ the value of the cat= numeric parameter from the query string into the new URL. You will need to preface this code with Options all or Options +FollowSymLinks.

    hmm ok enough …
    Hope that helps

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Redirecting http://www to http://’ is closed to new replies.