Redirect URLs using .htaccess
Posted by Raj
Redirect URLs using .htaccess :
You can use .htaccess to redirect users to a different URL(redirect a url)
Sometimes you need to redirect some URL and/or page on your site to another one.
using the “Redirect” directive:
Redirect /folder http://www.example.com/newfolder
Another useful directive is the RedirectMatch
RedirectMatch "\.html$" http://www.example.com/index.php
This will redirect all requests to files that end with .html to the index.php file.
One of the more powerful tricks of the .htaccess hacker is the ability to rewrite URLs
simple rewriting
all requests to whatever.htm will be sent to whatever.php:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [NC]
RewriteRule ^menu.html menu.php
Complex rewrite rule:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^Project/([^/]+)/([^/]+) /test.php?city=$1&file=$2 [NC]
would allow you to present this link as..
http://localhost/Project/Mumbai/CST
and in the background have that transparently translated, server-side, to..
http://localhost/test.php?city=Mumbai&file=CST
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
find the url,
how to make a url,
htaccess,
htaccess rewriting,
htaccess url,
mod-rewrite-for-seo-friendly-pages,
PHP interview questions and answers,
redirect 301,
redirect a url,
redirecting url,
short urls
.You can leave a response, or trackback from your own site.