mod_rewrite for many files

Discussion in 'Apache' started by lixor, Apr 28, 2006.

  1. #1
    hi

    I have the following in my .htaccess:
    
    RewriteEngine on
    
    RewriteRule ^index.html$ /index.php [L]
    RewriteRule ^contact.html$ /contact.php [L]
    
    RewriteRule ^polyphonic-ringtones/([^/]+),([^.]+)\.html$ /polyphonic-ringtones.php?sub=$1&pag=$2 [L]
    RewriteRule ^polyphonic-ringtones/([^.]+)\.html$ /polyphonic-ringtones.php?sub=$1 [L] 
    RewriteRule ^polyphonic-ringtones.html$ /polyphonic-ringtones.php [L]
    
    Code (markup):
    and it works perfect.

    but I have like 40 files (mp3-ringtones.php, true-tones.php, wallpapers.php...) on my site and I can't write 3 lines for each file so how can I write a rule for all my files in .htaccess. all this files can have only two, one or no parameter in the query string (like the example above)

    I red many threads before posting but still nothing about this.

    thanks
     
    lixor, Apr 28, 2006 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    Post current URL examples and how you want them. If the only change is the part before .php you can do it in one line, then a line for each ? and & that can be in the URL.
     
    Nintendo, Apr 28, 2006 IP
  3. lixor

    lixor Active Member

    Messages:
    73
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    68
    #3
    yes I know that can be done with only one line for each case, I found {REQUEST_URI} and {SCRIPT_FILENAME}, maybe this is what I need...

    first, all my pages are .php and they support only 2, 1 or no parameters

    I'm looking to a method to say:

    - "when you'll request from my site a file without any parameters return that file but with the .html" (e.g. you'll type w.site.com/polyphonic-ringtones.html and you'll see the content of w.site.com/polyphonic-ringtones.php, w.site.com/contact.html -> w.site.com/contact.php, w.site.com/index.html -> w.site.com/index.php and so on for mp3-ringtones.php, wallpapers.php...)
    - "when you'll request from my site a file with only one parameter return that page but with the .html in this form: thatfile/parameter.html" (e.g. you'll type w.site.com/mp3-ringtones/Top-downloads.html and you'll see the content of w.site.com/mp3-ringtones.php?sub=Top-downloads ... and so on for wallpapers.php, polyphonic-ringtones.php...)
    - "when you'll request from my site a file with two parameters return that page but with the .html in this form: thatfile/parameter1,parameter2.html" (e.g. you'll type w.site.com/wallpapers/Animals,4.html and you'll see the content of w.site.com/wallpapers.php?sub=Animals&pag=4 and so on for mp3-ringtones.php, polyphonic-ringtones.php...) pag is the number of page... and of course www not w :)

    I made this (like the example in my first post) and it works perfect but I add the rewrite condition for any files on my site and I have for 10 files + index.php + contact.php, 32 lines in my .htaccess and now I want to add more files... but I don't want to add 3 new lines for every file that I add...

    thanks nintendo, I know you are the mod_rewrite specialist :)
     
    lixor, Apr 29, 2006 IP