SitePoint Sponsor

User Tag List

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

    mod-rewrite about filename

    hi all,
    i did mod-rewrite in file .htaccess, it run, but i've a problem about filename in the same directory.

    For example:
    I've 2 file(s): common.php, welcome.php

    With URL is
    http://localhost/myfolder/data/provi...ry/hotel_name/

    i want to run file welcome.php

    if URL is:

    http://localhost/myfolder/data/provice_directory/
    i want to run file: common.php

    my code below: (its not okie, i think its wrong)

    RewriteRule ^(.*)/$ common.php?_url=$1 [L]
    RewriteRule ^(.*)/(.*)/$ welcome.php?_url=$1 [L]

    Thanks in advance

    Yen

  2. #2
    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,

    First, this is the PHP forum, not the Apache forum where mod_rewrite is discussed (a moderator will likely move this thread there shortly).

    Second, the .htaccess you're looking for (in the myfolder directory) is

    Code:
    RewriteEngine On
    RewriteRule ^data/provice_directory/hotel_name/$ welcome.php [L]
    RewriteRule ^data/provice_directory/$ common.php [L]
    NOTEs: (1) You didn't say where your welcome and common scripts were located so you may have to adjust their locations.
    (2) Doing this (as you'd specified) will take away your use of the default scripts in the two directories (provide_directory and it's subdirectory, hotel_name).

    If you'd like to learn a little more about Search Engine Optimization (SEO), have a look at the article at http://www.datakoncepts.com/seo and look in at the Apache forum.

    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

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi DK
    I'd visit your web for u sent, its great. Now my code run okie. Thanks a lot.

    PS: Sorry about that, but i think its PHP language b/s i use PHP to access .htaccess file. If i wrong, could u move it?

    Thanks an advance
    Yen

  4. #4
    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,

    Glad that my Search Engine Optimization (SEO) article helped you!

    I'm NOT a moderator here -- but I'd expected one of the PHP moderators to have moved this by now. No worries, I look at both forums and you got your answer and that's what counts, isn't it?

    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

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi DK,
    Sorry u again, I've a problem about that (Mod Rewrite)
    When i type an address:
    http://yentran/myfolder/Vietnam/CanTho/Asia
    i want to show:
    http://yentran/myfolder/Vietnam/CanTho/Asia/

    How about do it??

    Thanks for your help

    Yen

  6. #6
    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,

    It looks like you've changed things on me significantly -- or maybe not.

    Let's say that your "site root" folder is yentran/myfolder and that's where you'll put the .htaccess file (and that's where you'll be testing for th eother values. Let me further assume that Vietnam is the "data" directory you started with, CanTho the "province" directory and Asia the hotel.

    Code:
    RewriteEngine On
    RewriteRule ([A-Za-z]+)/([A-Za-z]+)/([A-Za-z]+) current.php?data=$1&province=$2&hotel=$3 [L]
    Okay, that may not be what you're looking for (to resolve your specific problem) but it should be enough to get you where you want to go.

    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

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi DK
    Thanks for reponse, but your code i'd work and it run okie, but it will show:
    http://yentran/myfolder/Vietnam/CanTho/Asia
    i dont like it
    I want to view http://yentran/myfolder/Vietnam/CanTho/Asia/ on my URL

    Yen

  8. #8
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Moved to a more appropriate forum

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  9. #9
    Non-Member
    Join Date
    Mar 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Re hi
    i'm ttyen, b/s i cant reply my topic in that rum, i dont understand so i must be register new account

    I have a question about that:
    When i use mod-rewrite with URL:
    http://www.abc.com/name/name1/filename.php?var=1&var2=2

    i use method $_GET but i only show all variable: name, name1 but i cant get variable after filename.php (e.g: var=1 and var=2)
    so i want to get all variable after filename.php

    thks
    Yen

  10. #10
    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)
    Hi Yen!

    If you're trying to propagate an existing query string through a mod_rewrite, you'll need to ADD the Query String Attached flag, i.e., the [L] becomes [QSA,L]. That'll make the redirected {QUERY_STRING} key1=$1&key2=$2&key3=$3&var1=value1&var2=value2.

    Okay?

    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

  11. #11
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:


    Hi ttyen I've sent you an email about your login issues, we should be able to fix you up right away I had to suspend your 2nd account as it goes against our guidelines, but your primary account is good to go.
    Mike
    It's not who I am underneath, but what I do that defines me.

  12. #12
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    about my account: i'd recived your email and post my question, thks your introduce.

    To DK: thanks a lot, it run..

    Yen

  13. #13
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Image name: img_sm_1090142081_facility-ex1-Lobby_thumb.jpg

    =>
    RewriteRule ^(.*)/images/([a-z_a-z_0-9_A-Za-z]+\-[a-zA-Z0-9_]+[a-zA-Z0-9])\.(gif|jpg)$ images/$2.$3

    OR

    RewriteRule ^(.*)/images/([a-z_0-9]+)/([a-z0-9A-Z_]+\-[a-zA-Z0-9]+\-[a-zA-Z0-9_]+)\.(gif|jpg)$ images/$2/$3.$4


    But it also that images?? hic

    Yen

  14. #14
    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,

    Pardon me but I'm not sure what you're trying to do.

    I see the image name is img_sm_1090142081_facility-ex1-Lobby_thumb.jpg

    I see that you want to rewrite SOMETHING (but I can't tell what it is) to images/filename.ext.

    Perhaps my lack of understanding is that, to specify the name of the image above, you only need regex to be ^images/([a-zA-Z0-9_-]+)\.(gif|jpg) and the redirect would, indeed, be images/$1.$2

    I'm not sure how Apache would try to interpret your repeated ranges within the first atom ($1) but it certainly upsets me as a human

    If I misinterpreted what you're trying to do, please correct me.

    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

  15. #15
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi DK
    i'd use your code, its great, current file .htaccess is complete. Thanks for support to me about that.

    Thanks again
    Yen

  16. #16
    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,

    Glad I could help!

    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

  17. #17
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi DK
    sorry again. But .htccess file is seem wrong b/s when i move the whole my code into another folder (E.g: all file (*.php) moved \source\). There is a problem

    Code:
    RewriteRule ^([a-zA-Z0-9_-]+)\.php$	source/$1.php [L]
    I must be run that URL below:
    http://localhost/root/myweb/source/

    => i dont want to show source folder
    i'd like show url:
    http://localhost/root/myweb/index.php (and the whole codeset will run in folder source)

    thanks for help
    Yen

  18. #18
    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)
    Hi Yen!

    Back again for more?

    While I should ask WHY you'd want to move all to a subdirectory (i.e., suggest you move it back), that wouldn't help others. However, since your code looks fine for what you've described AND your earlier posts had taken us through an horrendous series of subdirectories, I feel that the problem MAY be that you haven't provided enough information for us to resolve the current problem.

    Are you trying to redirect a filename.php REQUEST_URI from your myweb directory to serve it from the myweb/source subdirectory? If so, are there any characters other than (English) letters, digits, hyphen (-) or underscore (_) in the filename (before the .php extension)? Are there pseudo subdirectories similar to http://yentran/myfolder/Vietnam/CanTho/Asia?

    Another possible problem is that your localhost SHOULD be looking at the root directory by default, i.e., delete the "root/" in your http://localhost/root/myweb/source/ link (leaving http://localhost/myweb/source/).

    If I've "missed the boat" on these suggestions, please keep trying.

    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

  19. #19
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi DK
    In fact, you right.. when i write .htaccess file, that file have the same directories with all file (.php)... its run okie. But when i'd moved the whole codeset into subdirectory .. its wrong..

    E.g:
    C:\wwwroot\website\ => the all file .php
    => i want to create subdir (source folder)
    C:\wwwroot\website\source\ => that folder have the whole codeset (.php)
    so .htaccess file can't access .php file(s)

    URL:
    http://yentran/website/index.php OR http://localhost/website/index.php (the same link)

    That URL:
    http://yentran/website/Vietnam/CanTho/Asia
    => This is example

    u understand?

    Regards,
    Yen

  20. #20
    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,

    Yes, I think I understand AND I think I see what the problem might be: Apache gets confused when you switch directories with a mod_rewrite UNLESS you tell it the actual path to the script. In your case, **IF** you've used the rewriterules above, Apache thinks it's in the yentran/myfolder/Vietnam/CanTho/Asia directory.

    Two solutions: Either include the HTML BASE tag in the header (with the script's absolute address, i.e., http://yentran/website/index.php OR http://localhost/website/index.php)

    OR

    use absolute addressing in your .htaccess redirection, i.e.,

    Code:
    RewriteRule ^([a-zA-Z0-9_-]+)\.php$	http://yentran/website/source/$1.php [L]
    If I've figured out what the problem is correctly, either one should do it for you (and I'd use Option 1 'cause that would also maintain your relative links within the script - for your images, etc.).

    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

  21. #21
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi DK
    with your codeset

    Code:
    RewriteRule ^([a-zA-Z0-9_-]+)\.php$	source/$1.php [L]
    Its run
    But when i use the sublink that its wrong
    e.g:

    http://yentran/website/source/cantho/acc.php => its run
    http://yentran/website/cantho/acc.php => its not run (expection)


    Code:
    RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\.php$	source/$1.php [L]
    hic. i dont understand, why wrong?

    Thks DK
    Yen

  22. #22
    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,

    Okay, I do NOT know what (sample) URL you want to redirect and what the target path/filename is supposed to be. If you want to redirect http://yentran/website/source/cantho/acc.php => http://yentran/website/cantho/acc.php, use this in the .htaccess in the website directory:
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^source/
    RewriteRule ^(.*) source/$1 [L]
    WARNING! This will send ALL requests to the source directory!

    If you really wanted something else, please specify the source and destination that you want.

    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

  23. #23
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    HCM
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay, its so good, now Mod-rewrite run ...thks your support again

    Regards,
    Yen

  24. #24
    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,

    So glad to hear that it's Party Time all over 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
  •