htaccess redirect rewriterule parameters





htaccess redirect


Htaccess redirect

Learn htaccess redirect rewriterule flags , syntax using the sample example below.

301 Redirect using htaccess

If you want to redirect from an old document to new:


Redirect 301 /old/file.html http://yourdomain.com/new/file.html

Use following for redirecting Entire Directory.


1

RedirectMatch 301 /blog(.*) http://yourdomain.com/$1

Implementing a Caching Scheme with .htaccess

Cache the static files and improve your website’s performance.


# year
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>
#2 hours
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
</FilesMatch>

Redirect browser to https (ssl)

Add following snippet to your htaccess and redirect entire website to https.


RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Rewrite URLs using htacccess

Rewriting product.php?id=12 to product-12.html


RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1

Rewriting product.php?id=12 to product/ipod-nano/12.html


RewriteEngine on
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2

Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz


RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1

Redirecting the domain to a new subfolder of inside public_html


RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1


htaccess redirect syntax

htaccess redirect code on this is provided for your study purpose, it will guide you to know how to use mod_rewite to create .htaccess files on the apache servers. use it to practice and train your self online

All the tutorials on this site are free, the page code is provifed for you to use it to practice, if you want to help to improve and maintain this work, you can donate to us on.



Htacess tutorial guides withexamples and easy steps to set ip up on your server.


Htaccess Generator

Htaccess block all bad robots

prevent hack

redirect www to non www

modifying the environment variable

file access deny control

cache control no cache and cache public

ip blocking

adding new mime types and set timezone

hot to create file

hide .

gzip page compression

force file save

password protect a directory

hotlink protection

custom error page

stop directory listing

block and allow referrer

set cookie domain authentication

prevent directory listing

php 301 redirect

upload_max_filesize limit

301 redirect

changing home directory page

All the tutorials on this site are provided for free. You can copy and print the tutorials and code on this site, but you are not allowed to reproduce this information on another website. All rights reserverd 2012

Copywright © 2013 www.htaccessredirect301.com Site created By prince Ejike Google+

promo