SitePoint Sponsor

User Tag List

Results 1 to 15 of 15

Thread: Mod rewrite

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mod rewrite

    hi all,
    I'm newbie in forums. I've a problem about mod rewrite.

    This is my code (.htaccess file)

    RewriteEngine on

    RewriteRule ^(.*)/new_welcome\.php$ acc_welcome.php?_url=$1 [L]

    Its okie. Now it run file acc_welcome. But its not show images or css file in this file. I dont understand?

    Pls help me, thanks for help

    Yen

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is my code below: (in .htaccess file)

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^(.*)/images/(.*)\.(gif|jpg)$ images/(.*)\.(gif|jpg) [L]
    RewriteRule ^(.*)/hotel_welcome\.php$ mpo_hotel_welcome.php?_url=$ [L]

    but all images not show, i'd show properties of that images
    http://mydomain.com/me/folder1/folder2/images1.jpg
    but real url:
    http://mydomain.com/me/images1.jpg

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Siegen, Germany
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is my code below: (in .htaccess file)
    you cannot use RegEx in the substitution, I think you ment the back references.

    Better: Exit the rewriting, if the file exsistes physically
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.* - [L]

    RewriteRule ^(.*)/new_welcome\.php$ acc_welcome.php?_url=$1 [L]

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Siegen, Germany
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you cannot use RegEx in the substitution, I think you ment the back references.
    btw. this would be
    RewriteRule ^(.*)/images/(.*)\.(gif|jpg)$ /images/$2.$3 [L]
    RewriteRule ^(.*)/hotel_welcome\.php$ mpo_hotel_welcome.php?_url=$1 [L]
    Bob

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

    Your images have "disappeared" because you've told Apache that your script is in a different place. You will EITHER have to use absolute references OR keep your relative links in place but add the HTML BASE command in the HEAD section to tell Apache where the actual script is located (so that it can then find the links relative to that -- as you'd built them).

    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 Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn
    ttyen,

    Your images have "disappeared" because you've told Apache that your script is in a different place. You will EITHER have to use absolute references OR keep your relative links in place but add the HTML BASE command in the HEAD section to tell Apache where the actual script is located (so that it can then find the links relative to that -- as you'd built them).

    Regards,

    DK
    hi all, thanks for response

    But i'd use code above, but not show images (i dont understand)

    i use code:

    RewriteRule ^(.*)/images/logo\.gif$ images/logo.gif
    RewriteRule ^(.*)/images/backtotop.gif$ images/backtotop.gif
    RewriteRule ^(.*)/images/back_up.gif$ images/back_up.gif
    RewriteRule ^(.*)/images/regionmap.gif$ images/regionmap.gif
    RewriteRule ^(.*)/hotel_images/hotel_273/introduction_sm.jpg$ hotel_images/hotel_273/introduction_sm.jpg

    it run

    But when i use this code:
    RewriteRule ^(.*)/images/([a-zA-Z0-9]+)\.gif$ images/([a-zA-Z0-9]+).gif
    RewriteRule ^(.*)/hotel_images/hotel_([0-9]{1,3})/introduction_sm.jpg$ hotel_images/hotel_([0-9]{1,3})/introduction_sm.jpg[/B]

    => its not show images

    TO dklynn:
    I dont understand, can u explain clearly?

    Thanks for all
    Yen

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi dklynn
    ex: i've an images: abc-dbf_aaa.jpg

    this is my code in .htaccess file:
    RewriteRule ^(.*)/images/(([a-z]+)-[a-z_a-z]+)\.(gif|jpg)$ images/$2.$3

    but not show images??

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for all
    its run okie. I'd write wrong pattern in RewriteRule

    it right:
    RewriteRule ^(.*)/images/([a-zA-Z]+\-[a-zA-Z_a-zA-Z]+)\.(gif|jpg)$ images/$2.$3

    thanks again.
    Yen

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

    What you should do it remove those image rewrite rules and use:

    <base href="{insert website path and filename here}" />

    where website path and filename is the ... aw, just use the http://www.example.com/acc_welcome.php URL to the script. Then your relative links will work as they would if you were to ask for the acc_welcome script directly.

    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

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okie, thanks for all
    its run good.

    Yen

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

    You're welcome.

    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

  12. #12
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello again,
    I've a problem about that:
    for example:
    www.abc.com/home/index.php will be rewrite to www.abc.com/index.php (any file in folder HOME)

    my code below:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /home
    RewriteRule ^index\.php$ index.php

    Its wrong, i dont understand?? could you help me?

    Thank a lot!
    Yen

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

    Put this in the .htaccess in your root directory (www.abc.com):

    Code:
    RewriteEngine On
    RewriteRule ^home/(.*)$ index.php [L]
    That will take EVERY request for a file in the home directory and send it to the root directory's index.php file.

    BEWARE: Using a "catch all" like this can be dangerous as you will NOT be able to access anything out of the home directory (from a browser; EXCEPT php includes which, I believe, can access directly).

    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

  14. #14
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi DK

    With your code, its not run ...

    its run below:
    www.abc.com/index.php
    => it'll redirect to www.abc.com/home/index.php
    => not right

    I would to change, when i type my address: www.abc.com/home/index.php it'll be come www.abc.com/index.php

    Thanks for help
    Yen

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

    Did you put that .htaccess file in the home directory or the root directory as I suggested? Since it will work from root, I suspect you put it in the home directory, a subdirectory of the website root directory. Move it and try it again.

    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
  •