Jump to content

PHP_tyro

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

PHP_tyro's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi. I'm at the very early stages of my PHP learning, and find myself needing something that's beyond me at this stage. Hopefully someone can come to the rescue with appropriate code. What I need is a redirection facility on a WordPress site. Somewhere on the site might be a link that looks like this: http://www.mysite.com/news/ But I don't want there to be a page or folder called "news". Instead, in the redirection facility, "news" is associated with say the URL https://www.nytimes.com/pages/todayspaper/, and so clicking on http://www.mysite.com/news/ automatically jumps to the New York Times page in a new browser tab. There might be many such redirections, so I don't want a separate page or folder for each one. Ideally I could just enter the keyword ("news") and the target URL (https://www.nytimes.com/pages/todayspaper/) into a lookup list. I could do this easily in ASP, but now I'm moving to Linux hosts (better for WordPress) I need to get it done in PHP. Any assistance much appreciated.
  2. OK, after a bit more experimentation I can provide more accurate information than in the previous message. So as I said... I'm setting up a 404 redirect on a Linux server and have this line in .htaccess: ErrorDocument 404 /404handler.php That works fine EXCEPT when the nonexistent page that's called for has the extension .html -AND- there is subfolder involved. In other words, the redirect works for all these examples: http://www.MyDomain.com/DoesNotExist.htm http://www.MyDomain.com/DoesNotExist.php http://www.MyDomain.com/DoesNotExist.asp http://www.MyDomain.com/DoesNotExist.html http://www.MyDomain.com/BadFolder http://www.MyDomain.com/BadFolder/DoesNotExist.htm http://www.MyDomain.com/BadFolder/DoesNotExist.php http://www.MyDomain.com/BadFolder/DoesNotExist.asp But in this case: http://www.MyDomain.com/BadFolder/DoesNotExist.html There is no redirection and the browser just opens at the home page of http://www.MyDomain.com. I guess I must be missing something. Please tell me what it is.
  3. On the Linux server, the first line of .htaccess reads: ErrorDocument 404 /404handler.php That works fine for the example in the message above, where I was entering: http://www.MyActualDomain.com/BadFolder into the browser. However, if I browse to: http://www.MyActualDomain.com/BadFolder/DoesNotExist.html then the browser opens at the home page of: http://www.MyActualDomain.com I haven't put any redirection in 404handler.php yet, so it's not as if I'm being sent to 404handler.php then back to the home page. It's as if the ErrorDocument line in .htaccess is being ignored if a full URL including pagename.ext is entered into the browser. Any suggestions?
  4. Thanks for the response guys. Well, that was illuminating aschk, and I think it's given me the answer. I used your code snippet to see what information was revealed, and I came up with the following... If I browse to http://www.MyActualDomain.com/BadFolder and the 404handler.php is located on a Windows server, it doesn't appear as if I can get the name of /BadFolder at all. If I browse to the same nonexistent location and the 404handler.php is located on a Linux server, I can get /BadFolder from two variables: [REDIRECT_URL] => /BadFolder [REQUEST_URI] => /BadFolder The difference between those two, I'm not sure. Any enlightenment? Anyway, I can live with having 404handler.php on a Linux server. However I've just discovered another problem with this, which I'll post in a separate message.
  5. Hi folks. My server and web programming expertise is with Windows servers and ASP. My PHP is rudimentary at best, and I'm trying to learn as I go along while solving practical problems. What I need to do is redirect to a specified page on on a different domain when an invalid URL is entered into the browser. For example if: http://www.MyActualDomain.com/BadFolder/index.php does not exist, then the visitor is redirected to: http://www.MyOtherDomain.com/404handler.php As I understand it the conventional way to do that is via a redirect in the .htaccess file. I have done that and it worked fine. NOW FOR THE PROBLEM: A script in 404handler.php needs to know the bad URL that caused the 404. He is a snippet of test code I put together trying to figure out these environment variables: <? $host = getenv("REMOTE_HOST"); $referrer = getenv("HTTP_REFERER"); $path = getenv("REQUEST_URI"); echo "REMOTE_HOST = " . $host . "<br />"; echo "HTTP_REFERER = " . $referrer . "<br />"; echo "REQUEST_URI = " . $path . "<br />"; ?> REMOTE_HOST returns my own IP as expected, but the other two strings are empty. I've also tried $_SERVER['REQUEST_URI'] in place of the getenv method. Anyone got a solution? if it matters, here's PHPinfo on the server where 404handler.php resides: PHP Version 5.0.5 System Windows NT NT24 5.2 build 3790 Build Date Sep 5 2005 15:50:13 Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared" Server API CGI/FastCGI Virtual Directory Support enabled Configuration File (php.ini) Path C:\WINDOWS\php.ini PHP API 20031224 PHP Extension 20041030 Zend Extension 220040412 Debug Build no Thread Safety enabled Zend Memory Manager enabled IPv6 Support enabled Registered PHP Streams php, file, http, ftp, compress.zlib Registered Stream Socket Transports tcp, udp
  6. Yes, I've seen a few articles that talk about 301/302 and page rank, but I don't care about maintaining page rank in this case, because I'm referring/redirecting to sites not owned by me and over which I have no control. For example they might be sites for which I am an affiliate, or sites I am referring my visitor to for more information, or for a download or whatever. I guess in that case it probably doesn't matter whether I use 301 or 302? No, that's not a problem, I don't need to write them all out. I copied the lot in one go from the IIS server and used Microsoft Word to edit them from the ASP format to the format I quoted above, then pasted them back into Notepad. They are all converted to "Linux speak" and ready to go. The main reason I'd like to have them in a text file that could be automatically imported for server-side processing is for ongoing ease of maintenance. Just editing a text file and FTP'ing it to the server would be simpler and less dangerous than frequent messing with the .htaccess file.
  7. Hi all. I'm coming from an ASP environment and need to convert a website for hosting on Linux/Apache. I think I can handle most of it bit by bit, but there's one thing I need advice on. I have a 404.asp file that handles a lot of redirections. My explorations so far tell me that the way to handle redirection with Linux/Apache is to include a line like the following in the .htaccess file: redirect 302 /DICTIONARY http://www.dictionary.com Simple enough, but what bothers me about that method is the number of redirects that have to be inserted in the file -- at the moment it would add over 400 lines to .htaccess, and more will need to be added over time. Is the size of .htaccess an important consideration? Is there a better way to do this? I like the idea of having a single plain text file containing all the redirections and calling it into a server-side page for processing. Also, I don't understand the difference between 302 and 301 redirects. Temporary and permanent, yes, but what is the effective difference? Many thanks, Billy
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.