Redirects on a Website
These redirects assume an Apache server and work in the .htaccess file. It is placed at the root of the site and can be overridden in sub-directories.
We must distinguish the principle of redirect to that of URL-rewriting.
Summary
- Redirect vs. URL-rewriting.
- How to add www.
- How to redirect 404 errors on one page.
- Redirect a domain name to another.
- Redirect on a moved page.
- Redirect a whole directory to a single page.
Redirect vs. URL-rewriting
The two techniques are similar but have an opposite effect:
Redirect: The URL given by the user is redirected to a new page. The URL of the new page is displayed by the browser.
It is used for a change of address. The new URL should be indexed by search engines and the older removed.URL-rewriting: The URL given by the user is invisibly replaced by the server by a new path. However, the browser displays the URL given by the user.
It is used to separate the visible URL of the actual path and to provide users more convenient labels. Only the visible URL must be indexed by search engines and not the path on the server.Apache uses the same RewriteEngine module in both cases, but the Redirect command or 301 option change the URL displayed. In fact, the server sends the new URL to the browser that must make a new request.
Redirects should be placed before rewritings in .htaccess.
How to add www
How to redirect http://scriptol.com to http://www.scriptol.com
RewriteEngine On RewriteCond %{HTTP_HOST} ^scriptol.com RewriteRule (.*) http ://www.scriptol.com/$1 [R=301,L]How to redirect 404 errors on one page
This may be an error page, called page 404 that is the code returned when a page is not found, or the home page (most useful).
RewriteEngine onErrorDocument 404 /index.phpNote that the directive "RewriteEngine on" that activates the redirects is put once at the beginning of the .htaccess file.
Redirect a domain name to another
To change definitively the domain, the new domain beeing for example scriptol.com.
Redirect 301 / http://www.scriptol.com/For a temporary change you would use the code 302 instead.
Redirect on a moved page
Redirect 301 /directory/page.html http://www.scriptol.com/directory/page.htmlThis can be on the same site or another domain, nothing change as the domain is always included in the new URL.
Redirect a whole directory to a single file
If you want to remove a sub-directory from the Web, this can be achieved with a single command.
RedirectMatch 301 ^/mysubdir/.*$ http://www.scriptol.com/compiler/RedirectMatch 301 ^/mysubdir/.*$ http://www.scriptol.com/index.phpThe directory to remove is called "mysybdir" and the target is the index of another directory or a page.
The target must not be included in the directory to redirect because that will let enter an infinite loop.In terms of SEO, such an operation involves two conditions:
- It is preferable to place a page to "noindex" rather than redirect to another page whose content is different.
- You must ensure that all links pointing to a redirected page are updated. A link to a redirect on the same site let it penalized.
Use the link checker with options -r -s -f to find these links.More
Tuesday, July 24, 2012
Redirects on a Website
via scriptol.com
Labels:
CyberSecurity,
HACKING,
INFOSEC,
Technology
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment