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.

cant figure out simple rewrite

Discussion in 'Apache' started by sensoryaddict, Jul 10, 2011.

  1. #1
    After scouring the interwebs for hours with no luck.

    I come asking directly for help

    I would like to simply change my url from

    http://www.mywebsite.com
    http://www.mywebsite.com/index.php
    http://www.mywebsite.com/index.php?p=multimedia
    http://www.mywebsite.com/index.php?p=contact
    http://www.mywebsite.com/index.php?p=new

    to

    http://www.mywebsite.com
    http://www.mywebsite.com
    http://www.mywebsite.com/multimedia
    http://www.mywebsite.com/contact
    http://www.mywebsite.com/new


    I have tried everything I came across the web and I got nothing but server errors or no result at all

    Can somebody please help
     
    sensoryaddict, Jul 10, 2011 IP
  2. sensoryaddict

    sensoryaddict Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    is this very difficult?
     
    sensoryaddict, Jul 11, 2011 IP
  3. ntomsheck

    ntomsheck Peon

    Messages:
    87
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    RewriteEngine on
    RewriteRule ^index.php$ http://www.mywebsite.com/ [R=301,L]
    #(the dollar sign is very important in that instance)
    RewriteRule ^([^/\.]+)/?$ /index.php?p=$1 [L]
    #(this one is an exact copy from my website, with one vairable change [the p is an a in my query string] so I know it works)

    If those don't work, something else is amiss in your configuration.
     
    ntomsheck, Jul 11, 2011 IP
  4. sensoryaddict

    sensoryaddict Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks you

    This sort of works

    Now if I type http://www.mywebsite.com/index.php?p=multimedia it rewrites to http://www.mywebsite.com/?p=multimedia
    OR if I type http://www.mywebsite.com/multimedia it rewrites to http://www.mywebsite.com/?p=multimedia

    Is there a way to rewrite the url to a clean http://www.mywebsite.com/multimedia

    Will this cause issues retrieving the GET variable? I see it all the time. Sorry for the rudimentary understanding of rewrite, it's something I'm trying to wrap my head around

    The problem is I have a site live and I don't have the time to learn it in time to fix the urls
     
    sensoryaddict, Jul 12, 2011 IP
  5. ntomsheck

    ntomsheck Peon

    Messages:
    87
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It should not be doing any of that, unless there is code hiding in your page. Rewrite rules are just a translation between a shown url, and the url that's actually being sent to a web server. They wont redirect to a different URL unless one specifies a redirect. If you want it to redirect, you'll have to add a couple more lines:

    RewriteEngine on
    #RewriteRule ^index.php$ http://www.mywebsite.com/ [R=301,L]
    #(the dollar sign is very important in that instance)
    RewriteRule ^index.php\?p=([A-Za-z0-9]+)$ http://www.mywebsite.com/$1 [R=301,L]
    RewriteRule ^([^/\.]+)/?$ /index.php?p=$1 [L]
    #(this one is an exact copy from my website, with one vairable change [the p is an a in my query string] so I know it works)

    Copy that whole block into your .htaccess. I have commented out my first rewrite rule, as I believe it might be causing some sort of issue. Let me know if this does the trick as far as the fancy urls. Keep in mind, if all your links go to pages with query strings, every link your viewer clicks on will have to send a second request once redirected. Not a problem if they have fast internet, but they might not like it if they have dialup or mobile browsers.
     
    ntomsheck, Jul 12, 2011 IP
  6. sensoryaddict

    sensoryaddict Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thank you that absolutely worked!

    I changed my nav links to

    <li><a href="/">Home</a></li>
    <li><a href="multimedia">Multimdia/a></li>
    <li><a href="contact">Contact</a></li>
    <li><a href="new">New</a></li>


    I now have clean url's!! Thanks again
     
    sensoryaddict, Jul 12, 2011 IP