Mega list of redirects (.htaccess)
07-04-2010, 08:11 AM, (This post was last modified: 01-04-2011, 08:09 PM by HiddenKnowledge.)
#1
Mega list of redirects (.htaccess)
well lets start
but before we do red this lil snippet
notes on htaccess redirection

Quote:Always be sure to upload .htaccess files in ascii mode, sending it up as binary will break it (and usually make your server very, very unhappy.)

.htaccess does not work if you're on a windows server.

Make sure you triple check your changes. Clear your cache and look, test the server headers to make sure you see a 301 (that means its permanent) not a 302 (temporary) unless you are absolutely sure you really mean temporary.

Since some operating systems don't allow you to make a file without something before the "." you may need to save it as something.htaccess, some may even have to save it as htaccess.txt and change it once you've uploaded it.

Make sure your ftp program will show .htaccess files (FileZilla does and is free) It is a bit hard to edit something you can't see ;)

Double check that you're not overwriting an old one (some servers already place one there for your custom 404 pages etc.)

Make sure you replace example.com with your own sites URL

ok now lets begin are 1st one is 301 sounds crazy but lets go at it
for an single page
Code:
Redirect 301 /oldpage.html http://www.example.com/newpage.html

now for an entire site you do this
Code:
Redirect 301 / http://www.example.com/

now to change the end of it
Code:
RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php
Read:
Quote:This example is perfect if you've decided to switch to .php from .html pages. It will look for any .html page and redirect it to .php (ie http://www.example.com/yourpage.html and redirect it to http://www.example.com/yourpage.php). Now, be careful with this, it does mean any html page. I did this on one of my sites and had totally forgotten I had an iframe with .html content on some pages... I didn't notice for weeks that it was broken :S.
So learn from my mistake ;-) check, double check, then check again.

The most common meta redirect is
Code:
meta http-equiv="refresh" content="10; url=http://example.com/">
add < before meta
if i missed an feel free to say so
Reply
07-04-2010, 01:04 PM, (This post was last modified: 07-04-2010, 01:30 PM by RichardGv.)
#2
RE: Mega list of redircts
1. Thanks.
2. .htaccess works under both Windows and *nix versions of Apache, as far as the server is configured correctly (depends on AccessFileName and (kind of) AllowOverride).
http://httpd.apache.org/docs/trunk/howto/htaccess.html
(It's nevertheless true that Windows don't hide files with names starting with dot, unlike *nix systems.)
3. There's something that you may want to pay attention, about the directive Redirect:
Quote:Redirect Directive
...
Syntax: Redirect [status] URL-path URL
...
Then any request beginning with URL-Path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-Path will be appended to the target URL...
Source: http://httpd.apache.org/docs/2.2/mod/mod...l#redirect
So, for example, if somebody tries to access http://your-site.com/oldpage.html.old/testpage.html, and you have this rule in your .htaccess:
Code:
Redirect 301 /oldpage.html http://example.com/newpage.html
The result is, the user will be redirected to http://example.com/newpage.html.old/testpage.html. This exception can be troublesome in certain situations.
4. mod_rewrite provides a much more flexible solution that mod_alias for redirections, which you might be interested in:
http://httpd.apache.org/docs/2.2/misc/rewriteguide.html
5. About the example of the removal of .html extension, you can use mod_rewrite to avoid the problem that accesses to existing files are redirected incorrectly:
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)\.html$ $1.php [L,R=301]
Or you can choice to rewrite the request instead of redirecting it:
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)\.html$ $1.php [L]
(The code above is not tested. There can be certain issues when using them. The code originally came from Drupal .htaccess.)
Gentoo Linux User (w/ fvwm) / Loyal Firefox User / Owner of a Stupid Old Computer - My PGP Public Key

No man is an island, entire of itself; every man is a piece of the continent, a part of the main; if a clod be washed away by the sea, Europe is the less, as well as if a promontory were, as well as if a manor of thy friends or of thine own were; any man's death diminishes me, because I am involved in mankind; and therefore never send to know for whom the bell tolls; it tolls for thee.
-- Devotions Upon Emergent Occasions (1624), John Donn
Reply
07-06-2010, 09:22 PM, (This post was last modified: 01-04-2011, 08:09 PM by HiddenKnowledge.)
#3
RE: Mega list of redircts
Ok, two things.
Mone, check the spelling of your post (look at the topic...)
And the code blocks are not working, please use quote blocks.
With love,
HiddenKnowledge
A.k.a. Yoruichi Shihouin

If you have any questions, feel free to contact me trough email or pm. :)
Reply


Forum Jump: