Need help with my Mod_Rewrites. Spent over 3-4 weeks No Solution!

Discussion in 'Apache' started by mynyhart, Oct 9, 2010.

  1. #1
    I have stedily spent the past 3-4 weeks learning htaccess and mod-rewrites and everything about it. Reading writing Testing everything and im stumped on one problem.

    I have posted on many differnt forums, Even asked the creator of my graphics CMS, and my own server admin and no luck.

    I have redone my Code once again but only so i can try and finish up the last part of my Mod-Rewrite setup. So its very dynamic i believe but i will clean it up so it picks up less pages.
    
    # www.myspace-help.com/Backgrounds/?page=1 to 
    # www.myspace-help.com/Backgrounds-1.php
    RewriteRule ^([^/]+)-(\d+)\.php$ $1/?page=$2 [L,NC] 
    
    # www.myspace-help.com/Backgrounds/Saint_Patrics_Day/?page=1 to 
    # www.myspace-help.com/Background-Saint_Patrics_Day-1.htm
    RewriteRule ^([^/]+)-([^/]+)-(\d+)\.htm$ $1/$2/?page=$3 [L,NC] 
    
    # www.myspace-help.com/Background/view.php?cat=Saint_Patrics_Day&layout=19.gif to
    # www.myspace-help.com/Background-Saint_Patrics_Day-19.gif
    RewriteRule ^([^/]+)-([^/]+)-([^/]+)/?$ $1/view.php?cat=$2&layout=$3 [L,NC]
    
    Code (markup):
    The Problem i am having is with my last line. How can i make
    "www.myspace-help.com/Background-Saint_Patrics_Day-19.gif" become
    www.myspace-help.com/Background-Saint_Patrics_Day-19.html

    The problem i have is that i have many Image types. gif,jpg,and png
    The second Problem i am having with that last line is that It creates Duplicate Content.
    I have
    www.myspace-help.com/Background-Saint_Patrics_Day-19.gif
    and www.myspace-help.com/Background/view.php?cat=Saint_Patrics_Day&layout=19.gif

    But i can not figure out how to get anyone who goes to www.myspace-help.com/Background/view.php?cat=Saint_Patrics_Day&layout=19.gif to be 301'd to the new page www.myspace-help.com/Background-Saint_Patrics_Day-19.gif.

    The First two lines inside the CMS Script it has a 301 allready built in but the View.php Does not. And ive tried fooling with it and i cant do it threw the php so im trying to do it threw the htacess. I thought it would be simple....
    If anyone goes to www.myspace-help.com/Background/view.php?(.*) 301 to the real page or even a index but i cant get that to work.

    So TLDR

    # www.myspace-help.com/Background/view.php?cat=Saint_Patrics_Day&layout=19.gif to
    # www.myspace-help.com/Background-Saint_Patrics_Day-19.gif
    RewriteRule ^([^/]+)-([^/]+)-([^/]+)/?$ $1/view.php?cat=$2&layout=$3 [L,NC]


    How can i make
    www.myspace-help.com/Background-Saint_Patrics_Day-19.gif into
    www.myspace-help.com/Background-Saint_Patrics_Day-19.html
    or even
    www.myspace-help.com/Background/Saint_Patrics_Day-19/
    Keep in mind i have gif,jpg,and png files

    And how do i 301
    www.myspace-help.com/Background/view.php?cat=Saint_Patrics_Day&layout=19.gif to
    www.myspace-help.com/Background-Saint_Patrics_Day-19.gif

    or even 301 it to www.Myspace-help.com I just dont want any of the view.php? Pages to be shown so i dont have duplicate content.
     
    mynyhart, Oct 9, 2010 IP
  2. mynyhart

    mynyhart Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Also i have used so many dif Webtools, Read so many different Tutorials , and Even after idk how many hours spent learning and using the things i read, im still stumped!
     
    mynyhart, Oct 9, 2010 IP
  3. MrYu

    MrYu Peon

    Messages:
    157
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Something like this should do the trick, nothing else is needed:

    RewriteRule /Background/view\.php\?cat=(\w+)&layout=(\d+)\.(gif|jpg|jpeg|png)$ /Background-$1-$2.html [R=301,L]

    I think I got it right, but I haven't tested this.

    Keep in mind, this will match cat=....&layout=..., but it will not match layout=....&cat=..., so, depending on who/what generates the parameters, you might need to cover both cases and have two RewriteRules.
     
    MrYu, Oct 12, 2010 IP