1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

FAQ: mod_rewrite, 301 redirects, and optimizing Apache.

Discussion in 'Apache' started by Nintendo, Jul 30, 2005.

  1. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #121
    Domain.com/.htaccess

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^search/(.*)/$ search/search.php?q=$1

    domain.com/search/search.php?q=KEYWORD
    to
    domain.com/search/KEYWORD/
     
    Nintendo, Nov 8, 2005 IP
  2. unprofundity

    unprofundity Peon

    Messages:
    45
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #122
    thank you soo much sir nintendo! :)
     
    unprofundity, Nov 10, 2005 IP
  3. abdoh2010

    abdoh2010 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #123
    Dear Mr. Nitendo

    Could you please take a look on my .htaccess file, i think that it's need to orginize
    
    php_flag session.use_trans_sid off
    
    RewriteEngine On
    
    RewriteRule ^index\.html$ index.php
    RewriteRule ^top\.html$ top.php
    RewriteRule ^about\.html$ about.php
    RewriteRule ^adv\.html$ adv.php
    RewriteRule ^new_articles\.html$ new_articles.php
    RewriteRule ^lightbox\.html$ lightbox.php?%{QUERY_STRING}
    RewriteRule ^lightbox\.([0-9]+)\.html$ lightbox.php?page=$1&%{QUERY_STRING}
    RewriteRule ^search\.html$ search.php?%{QUERY_STRING}
    RewriteRule ^search\.([0-9]+)\.html$ search.php?page=$1&%{QUERY_STRING}
    RewriteRule ^search_new.html$ search.php?search_new_images=1
    RewriteRule ^cat\.html$ categories.php?%{QUERY_STRING} 
    RewriteRule ^cat([0-9]+)\.([0-9]+)\.html$ categories.php?cat_id=$1&page=$2&%{QUERY_STRING} 
    RewriteRule ^cat([0-9]+)\.html$ categories.php?cat_id=$1&%{QUERY_STRING}
    RewriteRule ^img([0-9]+)\.html$ details.php?image_id=$1&%{QUERY_STRING}
    RewriteRule ^img([0-9]+)\.([a-zA-Z0-9]+)\.html$ details.php?image_id=$1&mode=$2&%{QUERY_STRING}
    RewriteRule ^postcard([a-zA-Z0-9]+)\.html$ postcards.php?postcard_id=$1&%{QUERY_STRING}
    RewriteRule ^postcard\.img([0-9]+)\.html$ postcards.php?image_id=$1&%{QUERY_STRING}
    RewriteRule ^articles_category([0-9]+)\.html$ articles_category.php?topic=$1&%{QUERY_STRING}
    RewriteRule ^article([a-zA-Z0-9]+)\.html$ articles.php?id=$1&%{QUERY_STRING}
    
    RedirectMatch permanent ^/$ http://www.racing4e.com/index.html
    
    Code (markup):
    I would like also to use L and R and 301 but when I use it as your post it gave me internal error.

    Thank you and best regards, :)
     
    abdoh2010, Nov 14, 2005 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #124
    What's %{QUERY_STRING} doing in the code??!!

    Post a script URL, and how you want it.
     
    Nintendo, Nov 14, 2005 IP
  5. abdoh2010

    abdoh2010 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #125
    Dear Sir

    Thank you for your question

    %{QUERY_STRING} is what Chris in 4images.net advice us to use for url-friendly

    You could review his post to tike more understand of his logic

    http://www.4homepages.de/forum/index.php?topic=6729.0
     
    abdoh2010, Nov 14, 2005 IP
  6. abdoh2010

    abdoh2010 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #126
    Dear Sir,

    I am still waiting for your advice,

    Best regards, :)
     
    abdoh2010, Nov 15, 2005 IP
  7. Dekker

    Dekker Peon

    Messages:
    4,185
    Likes Received:
    287
    Best Answers:
    0
    Trophy Points:
    0
    #127
    I wanted to try, really I did nintendo....but my brain just melted...and I think I peed myself :(
     
    Dekker, Nov 15, 2005 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #128
    Make a post over in that thread. Looks like some crazy server if there suggesting %{QUERY_STRING} be there.
     
    Nintendo, Nov 15, 2005 IP
  9. anton-io!

    anton-io! Active Member

    Messages:
    540
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #129
    excellent thread! :)

    Maybe I missed it, but here goes ...

    I have 2 .xml files, one is generated with PHP (something.xml), while the other is static (sitemap.xml).

    How do you disable .htaccess from running php on the 'sitemap.xml' static file?

    here's what I got:

    
    Options +FollowSymLinks 
    rewriteEngine on 
    AddType application/x-httpd-php .xml 
    
    RewriteRule ^something(.*)\.htm$ something.php?ID=$1 [L]
    ..... 
    
    Code (markup):
     
    anton-io!, Nov 16, 2005 IP
  10. abdoh2010

    abdoh2010 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #130
    Dear Sir,

    Thank you for your reply,

    I don’t know what %{QUERY_STRING} do exactly, but by testing it I can say that it's slow down the redirect very much

    when I saw your thread and I read it, I got the understand that you are master in this issue and that is the reason that make me register in this forum to ask you for your advice and suggestion to make the code in a better way, :)

    Please be sure that I didn’t come here to give the impression that what I admonition is better of your thread here.

    Please fix the code for my.

    Best regards,
     
    abdoh2010, Nov 16, 2005 IP
  11. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #131
    php_flag session.use_trans_sid off
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index\.html$ index.php
    RewriteRule ^top\.html$ top.php
    RewriteRule ^about\.html$ about.php
    RewriteRule ^adv\.html$ adv.php
    RewriteRule ^new_articles\.html$ new_articles.php
    RewriteRule ^lightbox\.html$ lightbox.php
    RewriteRule ^lightbox\.([0-9]+)\.html$ lightbox.php?page=$1
    RewriteRule ^search\.html$ search.php
    RewriteRule ^search\.([0-9]+)\.html$ search.php?page=$1
    RewriteRule ^search_new.html$ search.php?search_new_images=1
    RewriteRule ^cat\.html$ categories.php
    RewriteRule ^cat([0-9]+)\.([0-9]+)\.html$ categories.php?cat_id=$1&page=$2
    RewriteRule ^cat([0-9]+)\.html$ categories.php?cat_id=$1
    RewriteRule ^img([0-9]+)\.html$ details.php?image_id=$1
    RewriteRule ^img([0-9]+)\.([a-zA-Z0-9]+)\.html$ details.php?image_id=$1&mode=$2
    RewriteRule ^postcard([a-zA-Z0-9]+)\.html$ postcards.php?postcard_id=$1
    RewriteRule ^postcard\.img([0-9]+)\.html$ postcards.php?image_id=$1
    RewriteRule ^articles_category([0-9]+)\.html$ articles_category.php?topic=$1
    RewriteRule ^article([a-zA-Z0-9]+)\.html$ articles.php?id=$1
    RedirectMatch permanent ^/$ http://www.racing4e.com/index.html

    A lot of those only work if they only have numbers. ([^.]+) covers a lot more.
     
    Nintendo, Nov 16, 2005 IP
    anton-io! likes this.
  12. abdoh2010

    abdoh2010 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #132
    Dear Nintendo,

    Thank you very much for fixing my code,
    I just add it to my web site and I can see that there is a different in speed

    I would like to use 301 redirect in all my links, so is it done by just adding [L,R=301] to the end of every line of RewriteRule and RedirectMatch ?

    Thank you again and best regards, :)
     
    abdoh2010, Nov 16, 2005 IP
  13. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #133
    Examples...

    RewriteRule ^shop/([^.]+)$ http://www.domain.com/$1/ [R=301,L]

    or for just one URL...

    RewriteRule ^whatever/$ http://www.domain.com/ [R=301,L]
     
    Nintendo, Nov 16, 2005 IP
  14. anton-io!

    anton-io! Active Member

    Messages:
    540
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #134
    Master Nintendo!

    Any thoughts on how to disable one file within .htaccess?

    If I have this in my .htaccess file ...

    
    AddType application/x-httpd-php .xml
    
    Code (markup):
    but want 1 file, like 'sitemap.xml', not to be parsed by php?

    All others are to be parsed (which works great!)

    Thank you x1000! :D
     
    anton-io!, Nov 16, 2005 IP
  15. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #135
    Something like...

    <FilesMatch "^sitemap\.xml$">
    AddType application/x-httpd-php .xml
    </FilesMatch>

    might do it, though I couldn't get this to do it last time I tried.
     
    Nintendo, Nov 16, 2005 IP
  16. anton-io!

    anton-io! Active Member

    Messages:
    540
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #136
    thank you for the quick reply!!!!

    That is exactly it - works AWESOME

    Thanks for your help!

    :D
     
    anton-io!, Nov 16, 2005 IP
  17. soul-healer

    soul-healer Peon

    Messages:
    1,459
    Likes Received:
    145
    Best Answers:
    0
    Trophy Points:
    0
    #137
    Hi,

    -I would like to share some of my thoughts on this thread.

    -I was scared to read about mod_rewrite each time i start reading a tutorial i was scared to create mess with my site. 5 Days back i read this thread and it looks so simple to me. In just 1 hour i converted by site dynamic URLs to Static html files. What a simple way to explain things. I started my site 16months back i would like to standout in the industry as in my country there is no such title call webmaster i hardly seen people from my country who do optimization and SEO work for a website some of the good sites i have seen are runned by people from my country but they live outside like USA nd UK so things are bit difficult for a person like me as server cost is high and it is impossible to have a sponsor.

    -This thread helps me alot, i learned how to play with mod_rewrite and i get the same results i was expecting. My site 771 pages was indexed by google and after implementing mod_write today google indexed over 9000 pages i would like to thanks Nintendo for starting such a thread that help me get better position. After doing all the optimization and with last google update i was ranking 80 for the most important keyword but today i am at 9th place visible on first page. Trafic is increasing from 1500 daily visitors to arround 4000 visitors.

    -I hope i will learn day by day from this forums many experience people are here which i considered my teacher that teach a person who have no resources in the country as no such technical education exits for website optimization and SEO work exits.

    -This thread help to achive a millestone as my site starts ranking better in google and increased visitors which help me earn money from my site aswell. I would like to thanks Nintendo once again for such a thread that helps me alot.

    -Also i would like to thanks all the members who contributed in thread and by reading their comments and questions i learned more.


    Regards.
     
    soul-healer, Nov 17, 2005 IP
  18. soul-healer

    soul-healer Peon

    Messages:
    1,459
    Likes Received:
    145
    Best Answers:
    0
    Trophy Points:
    0
    #138
    I have one question.

    If a Variable has spaces how to cut that spaces in the generate static page url
     
    soul-healer, Nov 18, 2005 IP
  19. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #139
    Editing the script to take it out in the URL, or search and replace it in to a _ or - is the only way I know of of geting rid of it.
     
    Nintendo, Nov 18, 2005 IP
  20. soul-healer

    soul-healer Peon

    Messages:
    1,459
    Likes Received:
    145
    Best Answers:
    0
    Trophy Points:
    0
    #140
    Does spaces hurt seach engine rankings ?
     
    soul-healer, Nov 18, 2005 IP