Rewrite URLs Using .htaccess Print

  • 0


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


Redirecting non www URL to www URL

RewriteEngine On
RewriteCond %{HTTP_HOST} ^viralpatel\.net$
RewriteRule (.*) http://www.viralpatel.net/$1 [R=301,L]


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



Was this answer helpful?

« Back