SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: alter the url

  1. #1
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    alter the url

    there is a url
    http://example.com/index.php/term/bo.xhtml.
    now i want to make it turn into http://example.com/bo.xhtml. how should i do,do use rewrite can ? any tips would be appreciated!
    Outdoor tools online store and wargame tools shop
    with best quality and service.
    comp molle tactical vest tactical clothing etc sell

  2. #2
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i want to use .htacess but i don't know whether it can achieve it.
    Outdoor tools online store and wargame tools shop
    with best quality and service.
    comp molle tactical vest tactical clothing etc sell

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    red,

    The only way that you can use index.php/term/bo.xhtml is to use Options +MultiViews. IMHO, it's a poor technique (to embed the script's filename in the middle of a URI).

    To "make it turn into bo.xhtml," create the links properly in your scripts!

    Okay, you're using the common misconception that mod_rewrite creates the "revised format" of the URI by guessing what your intention is. It does not! You must create the format of the redirection (the visible script) then generate regex to provide to mod_rewrite to enable Apache to serve a file (obviously, your intent is to serve index.php, not bo.xhtml).
    Code:
    # .htaccess in DocumentRoot
    RewriteEngine on
    RewriteRule ^([a-z]+)\.xhtml$ index.php/term/$1 [L]
    If you don't understand what I did, PLEASE read the mod_rewrite tutorial article linked in my signature ("Article") before you ask questions.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks for you answer.i copied and pasted you code to my .htacess file, there is no change on the url.
    the solvation of my problem is make a url redirection in .htacess file or make a url rewrite in .htacess file ?
    Outdoor tools online store and wargame tools shop
    with best quality and service.
    comp molle tactical vest tactical clothing etc sell

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    red,

    The code I supplies will take "files" in the DocumentRoot (of the request) with an xhtml extension and redirect (silently) to index.php/term/{extensionless_file_name_of_the_xhtml_doc}. If you want visitors to see the redirection ( ), then change [L] to [R=301,L].

    Didn't you read the tutorial?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thank you very much, i will read it right away.which is the solution of my problem? the
    url redirection in .htacess file or make a url rewrite in .htacess file ? thank you.
    Outdoor tools online store and wargame tools shop
    with best quality and service.
    comp molle tactical vest tactical clothing etc sell

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    redirect 301 /index.php/term/bo.xhtml http://example.com/bo.xhtml

    try this

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    seop,

    But, bo.xhtml can't be served! Remember, the index.php is the requested script (under Options +MultiViews) so you've done it backward.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  9. #9
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    yeap,i tried the way from seop.it didn't work.
    dklynn,
    can you tell me what is Options +MultiViews and Why do we use options +multiviews in rewrite rules?

    To "make it turn into bo.xhtml," create the links properly in your scripts!
    what does this line mean ? is that in my question i can't by use url redirect to change the url,in addition,i must do some changes in my sscripts. if this is right,can you tell me why i must do some changes to my scripts.
    Outdoor tools online store and wargame tools shop
    with best quality and service.
    comp molle tactical vest tactical clothing etc sell

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    red,

    MultiViews is a directive to Apache to tell it to serve the filename used in the path, i.e., your index.php script in the URI index.php/term/bo.xhtml. In that URI, I'm sure that you don't have a directory named index.php so MultiViews picks that file and allows it to read the term and bo.xhtml to select the contents to output.

    WHERE is Apache (or your visitors) going to find the directories index.php and term then request bo.xhtml? My point was that YOU must create these "fanciful" links (bo.xhtml in your DocumentRoot) within your scripts THEN create the mod_rewrite code to redirect to something Apache can serve (index.php/term/bo.xhtml).

    READ THE TUTORIAL! It's all there.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •