FAQ: mod_rewrite, 301 redirects, and optimizing Apache.

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

  1. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #221
    Sorry Nintendo doesn't work?? Confused....

    As mentioned before this below works but still takes the value after the '?'
    RedirectMatch 301 property_details/viewimage.php.* h tt p://www.costaandsierra.com/ [R=301,L]
     
    ian_ok, Feb 14, 2006 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #222
    In that code I don't see any ? or value so I'm not sure how that works, unless it moves it to the new URL because it's not in the code for the old URL.

    RedirectMatch 301 property_details/viewimage.php?imageID=([^.]+)&type=listing$ http://www.costaandsierra.com/ [R=301,L]

    I'm not sure if ([^.]+) works in
    RedirectMatch 301
    stuff.
     
    Nintendo, Feb 14, 2006 IP
  3. Agent47

    Agent47 Well-Known Member

    Messages:
    775
    Likes Received:
    138
    Best Answers:
    0
    Trophy Points:
    135
    #223
    Agent47, Feb 14, 2006 IP
  4. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #224
    It just copes the information by using the .*


    Correct it causes a 500 Error!

    Could I add some code to the viewimage file that would redirect it in 301 style to the homepage?
     
    ian_ok, Feb 14, 2006 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #225
    Make a post in the php board about editing the file.
     
    Nintendo, Feb 14, 2006 IP
    ian_ok likes this.
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #226
    Nintendo, Feb 14, 2006 IP
  7. Agent47

    Agent47 Well-Known Member

    Messages:
    775
    Likes Received:
    138
    Best Answers:
    0
    Trophy Points:
    135
    #227
    Thanks for the quick response. By this:
    http://www.site.com/flowers/###/rose/###.html you mean http://www.site.com/flowers/67/rose/21.html ?
    I actually want it to be http://www.site.com/flowers/rose.html :eek:
     
    Agent47, Feb 14, 2006 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #228
    Is this for just one URL, or a lot? If it's for more than one, you would have to have a .htaccess line for every single URL to have it that way with out the numbers.

    RewriteRule ^flowers/rose\.html$ detail.php?catID=67&itemID=21 [L]

    if there's only one URL.
     
    Nintendo, Feb 14, 2006 IP
  9. Agent47

    Agent47 Well-Known Member

    Messages:
    775
    Likes Received:
    138
    Best Answers:
    0
    Trophy Points:
    135
    #229
    Agent47, Feb 14, 2006 IP
  10. DSR

    DSR Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #230
    I won't be able to do it that way. The database is setup with the spaces. The + symbol works inbetween them, but not -. Is there a way through mod_rewrite to rename that %20 to something and then change the long url to a static one? Thanks again! :)
     
    DSR, Feb 14, 2006 IP
  11. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #231
    Internet_and_Web_Services is the part that changes and would be in the non_mod_rewrite version URL, along with all the other category names!!

    Only the script can change the links.
     
    Nintendo, Feb 14, 2006 IP
  12. DSR

    DSR Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #232
    DSR, Feb 14, 2006 IP
  13. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #233
    RewriteRule ^index2/17131\.html$ items/index2.php?item_id=17131 [L]
     
    Nintendo, Feb 15, 2006 IP
  14. DSR

    DSR Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #234
    Nintendo, you're the man. Thanks soooo much for all the help! I worked on my site for about 4 hours last night changing my scripts around to work with .htaccess and now, every page looks like a static .html or a directory. AWESOME! Re-crawled my site, and sent in a new sitemap to google. Looking forward to having better coverage in G :D :D :D
     
    DSR, Feb 17, 2006 IP
  15. pulkit

    pulkit Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #235
    Hi,
    I wanted to make subdomains without CPanel using .htaccess .
    What i want is to treat a subdomain like http://try.example.com] to http://www.example.com/try/ .
    I dont want to use CPanel in this.
    I tried a lot but no result.

    I read ur tutorial and tried that also.

    Here is the code that i tried:

    
    RewriteEngine on  
    RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$  
    RewriteCond %{HTTP_HOST} !^www\.example\.com$  
    RewriteRule (.*) http://www.example.com/%1$1 [P]
    
    Code (markup):
    I have also removed the $ sign after '.com' and tried but not working.

    My present Host is using CPanel.Could he possibly disabled the thing.

    Pls reply and help me out.

    Thanks and have a good day.
     
    pulkit, Feb 19, 2006 IP
  16. onedollar

    onedollar SEO Consultant for Hire

    Messages:
    3,481
    Likes Received:
    333
    Best Answers:
    0
    Trophy Points:
    0
    #236
    Can a htaccess interfere with proper functioning of subdomains?

    I have the following in my htaccess file

    but when I try to add a new subdomain in cpanel, it shows the content of mydomain.com everytime instead of subdomain.mydomain.com
     
    onedollar, Feb 24, 2006 IP
  17. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #237
    If you don't get an answer to that here, make a new thread with that question in the title. I'm a n00bie at sub-domain stuff.
     
    Nintendo, Feb 24, 2006 IP
    onedollar likes this.
  18. onedollar

    onedollar SEO Consultant for Hire

    Messages:
    3,481
    Likes Received:
    333
    Best Answers:
    0
    Trophy Points:
    0
    #238
    thanks Nintendo :)

    I could figure out the first 2 sections in the htaccess. but can you tell what does this stand for ?

    Thanks :)
     
    onedollar, Feb 24, 2006 IP
  19. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #239
    RewriteRule ^index\.(html|php|htm)$ /cgi-bin/cgi.php?index.$1 [L]

    Extension can be html, php, or htm, though I don't see a (.*) spot for the stuff at $1 to show up, unless it's the html, php, and htm part.


    RewriteRule ^aa\-(.*)\/(.*)$ /cgi-bin/cgi.php?$1/$2?%{QUERY_STRING} [L]

    I'm not sure about the %{QUERY_STRING} stuff. I've never had it in a RewriteRule line.
     
    Nintendo, Feb 25, 2006 IP
  20. onedollar

    onedollar SEO Consultant for Hire

    Messages:
    3,481
    Likes Received:
    333
    Best Answers:
    0
    Trophy Points:
    0
    #240
    actually, I was going to add sub-domain to an existing site and I found this in its htaccess file.
    since it is an existing site with good rankings in google, I didn't want to mess up anything :)
    have deleted the subdomain for the time-being.
    will see if someone can post here a reply or else will start a new thread.

    Thanks for your help, Nintendo :)
     
    onedollar, Feb 25, 2006 IP