URL Rewriting Tip with .htaccess File
Wall Script
Wall Script
Saturday, December 26, 2009

URL Rewriting Tip with .htaccess File

Some days back I had posted "Pretty URLs with .htaccess rewriting tips". In this post I had given one more pretty URL tip with .htaccess tip. I hope it's useful for you.

URL Rewriting Tip with .htaccess File


Book : The Definitive Guide to Apache mod_rewriteThe Definitive Guide to Apache mod_rewrite

Original URL:
Eg:http://twitter.com/followers.php?id=9lessons

Rewriting URL
Eg:http://twitter.com/9lessons/followers



.htaccess Code
RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)/\followers$ followers.php?id=$1

RewriteRule ^([a-zA-Z0-9_-]+)/\following$ following.php?id=$1
web notification

34 comments:

  1. nice :)

    i made one small demo from your twitter search box ;)

    http://ajax.chadan.in ( ignore some design errors )

    ReplyDelete
  2. Nice article but expand this tutorial like id=9lessons&sub=20&....

    ReplyDelete
  3. um, the rewrite rule should be":

    RewriteRule ^([a-zA-Z0-9_-]+)/\followers$ following.php?id=$1

    for the URL: http://twitter.com/9lessons/followers

    ReplyDelete
  4. Just to share I site i used as reference

    http://www.easymodrewrite.com/

    ReplyDelete
  5. Hi,

    I have some basic knowledge about how to url rewrite, but there is something I hope u can clarify:

    What I want is a url

    www.abc.com/software

    go to

    www.abc.com/index.php?cat=software

    I see a lot of examples that show: www.abc.com/folder/one

    matching with rewrite rule going to subfolder 'folder' but I want it to be rewritten to the index of the root.

    Or is there sumthing I'm missing out?

    Thanx in advance

    ReplyDelete
  6. Try this:

    ^([A-Za-z0-9_-]+)$ index.php?cat=$1

    Of course, this will treat any data trailing your '.com' as the category for your index.

    ReplyDelete
  7. Thanks dude....you solved my problem...

    ReplyDelete
  8. how to sett if it addon domain?

    ReplyDelete
  9. hi
    i can't run at localhost.
    Which server do you use?
    can help you.

    ReplyDelete
  10. i want to make all the links like www.domain.com/user
    user=several names and change by user.

    redirecto to usr/index.php?usr=user

    ReplyDelete
  11. This is called human-friendly URL (HFU), because
    man it is easier to remember or write

    ReplyDelete
  12. i want to hide the extension of a file on url after clicking it.

    ReplyDelete
  13. I want to click a link and it shows onl thefile name without the extension in url.

    ReplyDelete
  14. I want rewrite url : http://test.com/?t=content/>^*&id=1&page=1
    to http://test.com/content/>^*---1--page-1

    ReplyDelete
  15. http://localhost/Tagsoft1%28new%29/service_leftmenu.php?id=17

    i want
    http://localhost/Tagsoft1%28new%29/service_leftmenu/17

    by .htaccess and what changes should i do in my page links and menu

    ReplyDelete
  16. Hi, In my case it is working fine username.domain.com how can i change it to domain.com/username

    ReplyDelete
  17. Hi can you help me to write .htaccess file. I need to rewrite url as follows
    http://www.example.com/en/show?website=google
    to
    http://www.example.com/en/website/google

    any chance

    ReplyDelete
  18. nice script,
    any one know that how can i remove index.php from url joomla 1.5 version.
    I'm also used the sef setting but it's not working well and produced the 404 error.

    Please help me!!!!!

    Thanks

    ReplyDelete
  19. it worked , but with this my submit form dosent work as followers.php?id=$1 itworks well bu no with /9lessons/followers

    ReplyDelete
  20. Hello admin your code it not work how can i do admin ?

    ReplyDelete
  21. Hi sir!
    Pls help me how can i rewrite my urls fr0m

    www.site.com/exploits.php?id=1

    to

    www.site.com/exploits/1

    i vil be very thankful to yew!

    ReplyDelete
  22. hai,

    jquery is working in
    http://www.mysite.com/content.php?maincategory=software&sucategory=msoffice

    jquery is not working htaccess rewrite url
    example => http://www.mysite.com/software/msoffice

    can you help to fix this....thanks

    ReplyDelete
  23. Hi

    I want to convert my URL from
    http://mywebsite.com/microsite.php?action=PTU

    To

    http://mywebsite.com/PTU .
    Please help me..
    Thanks in advance

    ReplyDelete
  24. which one is correct .htaccess or htaccess.?

    ReplyDelete
  25. Hi

    I want to convert my URL from
    http://mywebsite.com/Discussion/index.php?qid=15

    To

    http://mywebsite.com/Discussion/56 .
    Please help me..
    Thanks in advance

    ReplyDelete
  26. RewriteRule ^Discussion/([0-9]+)$ index.php?qid=$1
    RewriteRule ^Discussion/([0-9]+)/$ index.php?qid=$1

    ReplyDelete
  27. sir please help

    http://mysite.com/web-site.php?pid=good-web

    I Create file .htaccess

    RewriteRule ^web-site/([a-zA-Z0-9_-]+)$ web-site.php?pid=$1
    RewriteRule ^web-site/([a-zA-Z0-9_-]+)/$ web-site.php?pid=$1

    Please help .
    Thanks in advance

    ReplyDelete
  28. http://sourabhgupta.com/onlinelearning_dbms

    Sir i want to show this url like

    http://sourabhgupta.com/view_project/onlinelearning_dbms
    How can i do that

    ReplyDelete

mailxengine Youtueb channel
Make in India
X