Timilsina Prakash's Blog
"Better to live one year as a tiger than 100 year as a sheep"

10 useful ways to rewrite URL using htaccess

I always had problem while rewriting URL. I almost always need to google for rewriting the URL. So, I am writing this post to let you know some of the common ways to rewrite URL. Now lets move to examples:

  1. rewriting domain.com/profile.php?user=prakash to domain.com/prakash
    You must be user of facebook.com. You can hit facebook.com/PracasTimilsina to get my fan page there, and facebook.com/eprakash.info for our blog's profile. Let me show you how this works using htaccess. When we set username in facebook.com, the profile will be changed to the username containing URL using htaccess. Now lets see the htaccess code for this:
    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1
    RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1
    here RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1 rewrites domain.com/profile.php?user=prakash to domain.com/prakash and
    RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1 rewrites domain.com/profile.php?user=prakash to domain.com/prakash/.
    In this way, both url; domain.com/prakash and domain.com/prakash/ works as domain.com/profile.php?user=prakash
  2. rewriting domain.com/article.php?id=5 to domain.com/article-5.html
    You can see different pages with .html extension in every article of my blog. Want to know how blogger manages this? see the example:
    RewriteEngine on
    RewriteRule ^article-([0-9]+)\.html$ article.php?id=$1
    as you can see here, article.php?id=5 can be redirected to article-5.html. In this code of htaccess, only number in ?id= is supported. you can see '([0-9]+)' there in the htaccess code which means the value of id can be from 0 to 9 and can be repeated(not only of 1 character). 
  3. rewriting domain.com/post.php?year=2011&month=01&article=new-article to domain.com/2011/01/new-article.html
    What example of URL you exactly see in my blog is :
    If you want the same in your website too, take the following code:
    RewriteEngine on
    RewriteRule ^([0-9]+)/([0-9]+)/([a-zA-Z0-9_-]+)\.html$ post.php?year=$1&month=$2&post=new-article
    whew, you're done. Use this code in your website to get the result. Remember, year and month are numeric in this case too.
  4. rewriting captcha.php to captcha.jpg
    Most of the website where captcha are used, you can see captcha.php in the image url. If you want to rewrite captcha.php to captcha.jpg in your website, simply paste the below code in your htaccess
    RewriteEngine on
    RewriteRule ^index.jpg$ index.php
    This is all what you want. I think this code is very easy to understand too
  5. Redirecting URLs without WWW to with WWW
    Have you ever noticed on facebook? while you enter facebook.com, it redirects to www.facebook.com. If you want to get this with you also, add these codes in your .htaccess file
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^eprakash\.info$
    RewriteRule (.*) http://www.eprakash.info/$1 [R=301,L]
  6. Launching website from new sub folder under public_html
    Just imagine if you change design of your website and uploaded in folder 'new' under public_html. Now, you need to launch website from new sub folder 'new' under public_html. Here is the code to do this:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^eprakash\.info$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.eprakash\.info$
    RewriteCond %{REQUEST_URI} !^/new/
    RewriteRule (.*) /new/$1
  7. Multiple domains in same root?
    This is useful only when you are in the unfortunate condition of hosting multiple domains from a same root folder. If you need to do this, you can paste the given code in your .htaccess file.
    #two domains served from one root..
    RewriteCond %{HTTP_HOST} domain-one.com
    RewriteCond %{REQUEST_URI} !^/one
    RewriteRule ^(.*)$ one/$1 [L]

    RewriteCond %{HTTP_HOST} domain-two.com
    RewriteCond %{REQUEST_URI} !^two
    RewriteRule ^(.*)$ two/$1 [L]
  8. Automatic Translation
    If you want your website to be automatically translated using google's translator, you can use .htaccess with the code given below:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^(.*)-fr$ http://www.google.com/translate_c?hl=fr&sl=en&u=http://corz.org/$1 [R,NC]
    RewriteRule ^(.*)-de$ http://www.google.com/translate_c?hl=de&sl=en&u=http://corz.org/$1 [R,NC]
    RewriteRule ^(.*)-es$ http://www.google.com/translate_c?hl=es&sl=en&u=http://corz.org/$1 [R,NC]
    RewriteRule ^(.*)-it$ http://www.google.com/translate_c?hl=it&sl=en&u=http://corz.org/$1 [R,NC]
    RewriteRule ^(.*)-pt$ http://www.google.com/translate_c?hl=pt&sl=en&u=http://corz.org/$1 [R,NC]
  9. Hide .php extension using .htaccess
    You may want to hide .php extension in your website. use this code in your .htaccess to do that
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^(.*)\.htm$ $1.php [nc]
  10. Use suffix of '/' always using .htaccess
    This is quite simple to do and understand, See the code below:
    RewriteRule ^folder\/sub$ folder/sub/ [L,R=301]
Share if you have more via comment :)

43 Responses to “10 useful ways to rewrite URL using htaccess”

Anonymous said...

January 28, 2013

I'm really enjoying the design and layout of your site. It's a very easy on
the eyes which makes it

much more pleasant for me to come here and visit more often.
Did you hire out a developer to create

your theme? Excellent work!

Feel free to surf to my page :: blogallangraphic.wordpress.com
My website - properties in Murcia

Anonymous said...

January 28, 2013

Hmm it looks like your blog ate my first comment (it was super long) so I guess

I'll just sum it up what I wrote and say, I'm thoroughly enjoying your blog.
I as well am an

aspiring blog writer but I'm still new to the whole thing. Do you have any

recommendations for rookie blog

writers? I'd certainly appreciate it.

My web page ... http://www.otaiweb.com
My page: virus lab 2009

Anonymous said...

January 28, 2013


my web page: http://vps2102.vps.host.ru/index.php/Review:_Una_Nautica_In_the_Around_Finestrat_The_country_tutorial_A_lot_more_than_90_Merchants_And_Restaurants
Also visit my blog ; Alicante Spain property

Anonymous said...

January 28, 2013

I just couldn't depart your site before suggesting that I

actually enjoyed the standard information a person provide for your visitors? Is going to be back often to check up on new posts

My blog post http://lan.helsingkrona.se/mediawiki/index.php?title=Water_Used_again_-_Your_Must-Know_Guide_on_Drinking_water_Efficiency
Here is my web page weather spain year round

Anonymous said...

January 29, 2013

There are actually lots of details like that to take into consideration.
That may be a great point to carry up. I offer the thoughts above as

common inspiration however clearly there are questions like the one you

bring up where the most important thing

can be working in sincere good faith. I

don?t know if greatest practices have emerged round things like that,
but I am certain that your job is clearly recognized as a fair game.
Both girls and boys really feel the influence of only a moment’s

pleasure, for the remainder of their lives.

My blog: http://graciebellabutterfly.blogspot.com/
Also see my webpage: accommodation in Dolores Spain

Anonymous said...

January 29, 2013

A large percentage of of the

things you state is astonishingly

appropriate and it makes me ponder why I hadn't

looked at this in this light before. Your piece really did

switch the light on for me as far as this subject goes. Nonetheless at this time there is one

particular factor I am not too comfortable with

and whilst I attempt to reconcile that with the actual central

idea of your point, permit me observe just what all the

rest of your visitors have to say.Well done.

my weblog; kpabroadinspain.blogspot.com
Here is my page ... homes for deal in Elche Spain

Anonymous said...

January 29, 2013

I keep listening to the reports

talk about receiving free online grant applications
so I have been looking around for

the finest site to get one. Could you tell me please, where could i get


Feel free to surf to my page :: conteudo.marista.edu.br
Here is my blog post :: forums costa blanca spain Granada

Anonymous said...

January 29, 2013

Pretty portion of content. I simply stumbled

upon your website and in accession capital to assert that I get actually
enjoyed account your blog posts. Any way I will be subscribing
to your augment or even I success you access persistently rapidly.

My web page ... http://essentialweb.asia
my page - department of transportation drug testing

Anonymous said...

January 29, 2013

I want to convey my respect for your kindness giving support

to persons that really

want help with that issue. Your real dedication

to passing the message along had been really

invaluable and has all the time helped women just like me to achieve their aims.

This warm and friendly key points signifies

much to me and

extremely more to my mates. Best wishes; from all of us.

My web page: ukinsulationgrants.com
My website :: rent a car spain solmar

Anonymous said...

January 29, 2013

There are actually a

variety of particulars like that to take into consideration.
That may be a nice level to deliver up. I provide the ideas above as

basic inspiration however clearly there are questions just
like the one you

deliver up the place a very powerful thing

will likely be working in honest good faith. I

don?t know if best practices have emerged round issues like that,
however I am sure that your job is clearly identified as a good game.
Both girls and boys really feel the affect of just a moment’s

pleasure, for the rest of their lives.

Also visit my web-site http://magarto.com/
Here is my web-site extremadura fishing

Anonymous said...

January 29, 2013

I wish to express my appreciation for your generosity
supporting those individuals that really need help on

this particular

study. Your very own commitment to getting the solution up and down had become surprisingly

significant and has in most cases encouraged professionals much like me to reach
their dreams. Your helpful information implies a lot to me and even further to my mates.
Thank you; from everyone of us.

Also visit my web page - arisf.com
Also see my webpage :: traditional hunting bows

Anonymous said...

January 30, 2013

I was very happy to find this web-site.I wished to thanks on your time for

excellent learn!! I positively having fun with every

little little bit of it and I've you bookmarked to take a look at new stuff you

weblog post.

Here is my web site - http://topseobacklinks.com
Feel free to surf my homepage weather spain march

Anonymous said...

January 30, 2013

Hi! This is kind of off topic but I need some

guidance from an established blog. Is it tough to set up your
own blog? I'm not

very techincal but I can figure things out pretty quick. I'm
thinking about setting up my own but

I'm not sure where to start. Do you have any points or suggestions? Cheers

Here is my web page http://savannahawk.seobybookmarks.com/user/profile/dionbryant70
My page :: british expat forums spain Benissa

Anonymous said...

January 30, 2013

I'm really impressed with your writing talents as neatly as with the layout on your

blog. Is that this a paid subject or did you modify it

your self? Anyway stay up the nice quality writing, it is

uncommon to see a nice blog like this one these days..

Look into my web blog economarx21.wordpress.com
Feel free to visit my web site - low fat salad recipes

Anonymous said...

January 30, 2013

I have been browsing online more than 3 hours today, yet I never found
any interesting article

like yours. It is pretty worth enough for me.
In my view, if all webmasters and bloggers made good content as you did, the web will be a

lot more useful than ever before.

My weblog - http://www.defenceblog.org/2011/01/defencepk-is-down-for-today.html
Take a look at my blog post :: immigration spain news Cartagena

Anonymous said...

January 30, 2013

Hey there! Would you mind if I share your blog with my
facebook group? There's a lot of folks that I think would really appreciate your content.

Please let me know. Thanks

Feel free to surf to my blog post; tecnidoc09.bibliosistemas.com.ar
Feel free to surf my page used cars spain sevilla

Anonymous said...

January 31, 2013

Heya i am for the first time here. I came across this board and I find It truly useful
& it helped

me out a lot. I hope to give something back and help others like you aided me.

my site; https://bendrauk.ktu.lt/profile/VictorinaBradley1983
Here is my website :: Look At This

Anonymous said...

January 31, 2013

Write more, thats all I have to say. Literally, it seems as though you relied on the video to make
your point. You

obviously know what youre talking about,
why throw away your intelligence on just posting

videos to your site when you could be giving us something enlightening to read?

Feel free to surf to my web site: http://cupe.tu-bs.de/index.php?title=User_talk:BobetteArnold82
Feel free to surf my homepage :: Emigrate

Anonymous said...

January 31, 2013

Hi there! Quick question that's completely off

topic. Do you know how to make your site mobile friendly? My site looks weird when

viewing from my iphone 4. I'm trying to find a
theme or plugin that

might be able to correct this issue. If you have any recommendations, please

Appreciate it!

Look into my blog post ... newturan.com
Feel free to surf my web site act ii microwave popcorn

Anonymous said...

February 08, 2013

you're really a good webmaster. The web site loading speed is amazing. It seems that

you're doing any unique trick. Also, The contents

masterwork. you've done a excellent job on this topic!
Look at my web blog ; http://stage.www.controlglobal.com/wikis/lost_companies/index.php?title=User_talk:KaterineBarnes90

Anonymous said...

February 21, 2013

Greetings from Colorado! I'm bored at

work so I decided to browse your site on my iphone during lunch break. I

love the info you present here and can't wait to take a look when I get home.

amazed at how fast your blog loaded on my cell phone .. I'm not even
using WIFI,

just 3G .. Anyways, awesome blog!
Also visit my blog post : www.seocome.com

Anonymous said...

March 01, 2013

Hello there! This is my first visit to your blog! We are a

group of volunteers and starting a new initiative in a community in the same
niche. Your blog

provided us useful information to work on. You have done a extraordinary job!
Check out my webpage : socialcircle.stock-options-picks.com

Anonymous said...

March 07, 2013

Hello there, just turned into alert to your blog thru
Google, and found that it is really informative. I am gonna

watch out for brussels. I will be grateful for those who proceed this in future.

Many people can be benefited from your writing.

my website: www.script-pag.com

Anonymous said...

March 10, 2013

As I web-site possessor I believe the content matter here is rattling

fantastic , appreciate it for your hard work. You should keep it up forever!

Best of luck.
My website :: www.Authenticlinks.com

Anonymous said...

March 10, 2013

certainly like your website but you have to check the

spelling on quite a few of your posts. Several of
them are rife with spelling issues

and I find it very troublesome to tell the truth nevertheless I will surely come

back again.
Also visit my webpage http://www.romanlegion.com/wiki/index.php?title=Live_The_Desired_With_VW_Campervan_Hire_Spain

Anonymous said...

March 13, 2013

Hello there! This is kind of off topic but I need some

guidance from an established blog. Is it difficult to set up your own blog?
I'm not

very techincal but I can figure things out pretty quick. I'm thinking about creating my own but

I'm not sure where to start. Do you have any tips or suggestions? Cheers
Also visit my webpage :: http://co2gerechtigkeit.de

Anonymous said...

March 16, 2013

Youre so cool! I dont suppose Ive learn anything like this before.
So good to seek out any person with some authentic ideas

on this subject. realy thanks for beginning this up.
this web site is one

thing that's needed on the net, somebody with a little bit originality. helpful job for bringing one

thing new to the web!
Also visit my site ... heybebo.com

Anonymous said...

March 26, 2013

Its such as you read my thoughts! You appear
to grasp so much approximately this, like you wrote the e book in it or
something. I feel that you simply can do with
some percent to

pressure the message home a bit, but instead of that,

this is magnificent blog. An excellent read. I

will definitely be back.
Look at my homepage ; blazer-scans.blogspot.ru

Anonymous said...

April 10, 2013

jixpmjo fntrtp [url=http://sbac.org/de/monclereaby.aspx]moncler outlet[/url] zinexc [url=http://sbac.org/de/monclereaby.aspx]moncler online shop[/url] nccqrc [url=http://www.deralphlaurensaleoutlet.info/]ralph lauren outlet[/url] lshues [url=http://www.longchampoutletsttaschen.info/]www.longchampoutletsttaschen.info[/url] nxjzki [url=http://www.deralphlaurensaleoutlet.info/]ralph lauren sale[/url] yzpkyc [url=http://www.deralphlaurensaleoutlet.info/]ralph lauren[/url] nyswgf tzvhznp

Anonymous said...

April 19, 2013

A person essentially help to make seriously posts I would state.
This is the very

first time I frequented your web page and thus far?
I amazed with the research you made to

make this particular publish extraordinary. Great


Have a look at my blog post: http://videos.sweethazzard.com/read_blog/15067/chennai-classifieds

Anonymous said...

April 21, 2013

It’s hard to search out knowledgeable

individuals on this matter, but you sound like you already know what you’re speaking about!

Feel free to visit my site - http://Woodhull.tv/social/pg/profile/ShizukoHarris71

Anonymous said...

April 26, 2013

You can certainly see your expertise within the paintings you

write. The arena hopes for more passionate writers like you

are not afraid to mention how they believe. All the time
go after your heart.

Look into my webpage http://www.Impairmentsimulator.com/?q=node/367314

Anonymous said...

May 26, 2013

Cars and trucks are guys best toys. This information is relayed back to whoeverdid the barcode label Stickers Design Your Own.
'It is an emotion Robinson is determined not to experience again in the first group of Stickers Design Your Own, call The Decal Factory and ask one of their daily naps. To begin with, what exactly constitutes a large banner print? Then, select 'My Uploads' tab that is present below the 'stickers design your own' tab on the Excel ribbon. Knowing this will spoil the look of your stickers design your own.

my blog ... vinyl sticker

mao qiuyun said...
October 30, 2015

oakley sunglasses
tiffany and co jewelry
chanel handbags
michael kors factory outlet
oakley sunglasses
coach outlet online
nike huarache
louis vuitton outlet
north face jackets
michael kors outlet
pandora jewelry
ugg outlet
beats by dr dre
lululemon outlet
oakley sunglasses
canada goose jackets
michael kors outlet online
michael kors outlet
michael kors outlet store
lululemon outlet
coach outlet
ralph lauren outlet
longchamp handbags
replica watches
michael kors wallet
adidas outlet store
prada outlet
calvin klein underwear
ugg boots

John said...
January 14, 2016

louis vuitton handbags
canada goose jackets
kate spade handbags
ralph lauren outlet
ralph lauren outlet
nhl jerseys
ray ban sunglasses outlet
the north face outlet
michael kors outlet
adidas superstars
ray ban sunglasses outlet
uggs australia
retro 11
cheap oakley sunglasses
tory burch shoes
official coach factory outlet
fake oakley sunglasses
oakley sunglasses
nike huarache shoes
cheap toms
ray ban sunglasses
cheap jerseys
abercrombie & fitch new york
ray ban sunglasses
ugg sale
fitflop clearance
michael kors outlet online
michael kors uk
ray ban sunglasses uk
true religion jeans
oakley sunglasses sale
hollister jeans
michael kors
nfl jerseys wholesale
tiffany and co
michael kors handbags
michael kors outlet
michael kors outlet online

Yuanyuan Lin said...
May 08, 2016

5.09llllllyuantrue religion jeans
true religion outlet
true religion jeans
fitflops sale clearance
fitflops sale
fitflops shoes
michael kors outlet
michael kors outlet
tiffany and co
tiffany jewellery
beats by dr dre
beats by dre
oakley sunglasses
oakley sunglasses
ray-ban sunglasses
ray ban sunglasses
hollister uk
lululemon outlet
rolex watches
mulberry handbags

محمد الخطيب said...
July 09, 2016

شركة كشف تسربات المياه بالرياض
كشف تسربات المياه بالرياض
شركة عزل اسطح بالرياض
شركة عزل خزانات المياه بالرياض
شركه عزل مائى بالرياض
شركة عزل حرارى بالرياض
شركة ترميم منازل بالرياض
شركة مكافحة حشرات بالرياض
شركة رش مبيدات بالرياض
شركة تسليك مجارى بالرياض

شركة كشف تسربات المياه بالدمام
كشف تسربات المياه بالدمام
شركة عزل اسطح بالدمام
شركة عزل خزانات المياه بالدمام
شركه عزل مائى بالدمام
شركة عزل حرارى بالدمام
شركة ترميم منازل بالدمام
شركة مكافحة حشرات بالدمام
شركة رش مبيدات بالدمام
شركة تسليك مجارى بالدمام
شركة ترميم منازل بالدمام
شركة صيانة منازل بالدمام

xjd7410@gmail.com said...
July 16, 2016

gucci handbags
christian louboutin shoes
beats headphones
jordan retro 3
oakley sunglasses
jordan 6
coach factory outlet
jordan concords
oakley sunglasses
nike air jordan
cheap oakleys
toms shoes
pandora jewelry
louis vuitton outlet
coach outlet
nike trainers
abercrombie & fitch
true religion jeans
cheap jordan shoes
nike blazers
louis vuitton handbags
louis vuitton
gucci outlet
kevin durant shoes
air jordans
michael kors handbags
celine handbags
timberland boots
true religion outlet
nike air force 1
longchamp handbags
coach outlet store online
jordan shoes
coach outlet
cheap jordans
michael kors outlet
nike factory outlet
louis vuitton outlet
hollister clothing
rolex watches

dada24 Xu said...
August 25, 2016

nmd adidas
true religion jeans outlet
ugg boots
cheap jordan shoes
ugg outlet
uggs outlet
ray bans
true religion jeans outlet
ugg boots outlet
kate spade uk
montblanc pens
louis vuitton outlet online
michael kors outlet clearance
fitflops outlet
louis vuitton handbags
bottes ugg pas cher
ray ban outlet
yeezy boost 350 white
michael kors purses
cheap nfl jerseys
pandora charms outlet
coach outlet online
polo ralph lauren outlet online
ralph lauren
louis vuitton outlet online
nike roshe run
cheap jordan shoes
ugg boots outlet
coach outlet online
jordan retro
celine outlet online
yeezy boost 350 balck
tiffany jewelry
michael kors canada
versace sunglasses wholesale

fangyaoting said...
August 29, 2016

nfl jersey wholesale
adidas nmd
rolex watches
ugg sale
omega watches
prada handbags
michael kors wallet sale
mulberry outlet
christian louboutin outlet
supra shoes
ugg boots on sale
michael kors handbags
cheap soccer jerseys
louis vuitton bags cheap
ugg outlet uk
dior sunglasses
michael kors outlet
michael kors outlet
ugg outlet
michael kors factory outlet
fitflop sale
mac cosmetics sale
longchamp handbags
swarovski jewelry
toms shoes
coach outlet online
fitflops shoes
nike outlet online
michael kors outlet
ugg boots

Qinan Chen said...
September 13, 2016

hollister co
ugg outlet
[url=http://www.uggs-australia.it][b]ugg boots[/b][/url]
[url=http://www.monclerjacketsuk.org.uk][b]moncler jackets[/b][/url]

Qinan Chen said...
September 13, 2016

nike sneakers
michael kors bags
discount nike shoes
christian louboutin uk
kate spade outlet
coach factory outlet online
oakley sunglasses wholesale
cheap ray ban sunglasses
polo ralph lauren outlet online
hollister uk
coach outlet online
canada goose jackets
coach factory outlet online
adidas outlet store
toms outlet store
longchamp handbags
polo ralph lauren outlet online
canada goose outlet
michael kors outlet online
louis vuitton outlet online
louis vuitton outlet online
longchamp handbags
canada goose sale
jordan shoes
ray ban sunglasses discount
celine handbags
ugg boots
cheap jerseys
michael kors outlet clearance
ralph lauren outlet online
true religion sale
louis vuitton borse
longchamp bag
polo ralph lauren
mlb jerseys
rolex watches for sale
nike air huarache
cheap oakley sunglasses

dada24 Xu said...
September 24, 2016

ray ban sunglasses
cheap ray bans
uggs outlet
uggs outlet
uggs on sale
nike free flyknit
pandora bracelet
red bottoms shoes
nike shoes for men

Post a Comment

Please drop a comment on the above post :)

Search This Blog



Email Subscription

Enter your email address: