www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] rewrite writes new url in browser

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440

    resolved [RESOLVED] rewrite writes new url in browser

    I have a rather simple rewrite I am trying to implement but it does not work the way I want it too.

    Code:
    RewriteEngine on
    RewriteRule ^([0-9]+)/([0-9]+)/$ /index.php?id=$1&arc=$2 [r=301,L]

    What I want is enter: http://www.mywebsite.com/2009/3/ and get

    http://www.mywebsite.com/index.php?id=2009&arc=3

    I want my server to see the second (real) address, but the users browser to see (keep) the original address. The browser gets redirected to the php address instead of keeping the more friendly address. What am I doing wrong?

  2. #2
    Join Date
    Apr 2009
    Posts
    8
    RewriteEngine on
    RewriteRule ^/([0-9]+)/([0-9]+)/$ /index.php?id=$1&arc=$2 [r=301,L]

    tried with beggining slash?

  3. #3
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    Adding / breaks the rewrite all together.

    Maybe I wasn't clear what I want.

    I want the address to look like this in the browser

    http://www.mywebsite.com/2009/05/

    but the server needs

    http://www.mywebsite.com/index.php?id=2009&arc=5 to actually see the desired page.

    I thought the idea of a rewrite versus a redirect was to allow the browser to see a cleaner address. I get the rewrite to the correct page. The problem is the browser sees the second URL not the first one like I want.

  4. #4
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    I found a web site ( http://www.generateit.net/mod-rewrite/ ) that creates rewrite code for you. It came up with this;


    Code:
    RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?id=$1&mo=$2 [L]
    With this code the friendly URL has to look like this :

    http://www.mywebsite.com/2009/5.html

    which it rewrites to :

    http://www.mywebsite.com/index.php?id=2009&mo=5

    But the browser does stay with the original URL which is what I want.

    It leaves the browser with the more friendly URL, but what a mess my webpage was. No formatting what so ever. How do I get my CSS pages to load correctly? I also have other pages (php includes) that appear messed up or not found.

    Does the directive RewriteBase / fix that? It doesn't seem too.

  5. #5
    Join Date
    Mar 2009
    Location
    Yorkshire
    Posts
    266
    Yeah this is a problem i faced, simply use full URL's to link to stylesheets,imgs etc..........i do this by saving SITE_ROOT in a mysql database and using that on all of them. Just depends on how your site was set up.

    Ryan

    P.s it shouldnt mess with your PHP includes as it uses the server location rather than the web location of the file your including

  6. #6
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    I came up with a set of rewrite rules that pretty much covers my site.

    Code:
    RewriteEngine On
    RewriteRule ^([0-9]+)/([a-zA-Z0-9-]+)\.html$ /index.php?id=$1&title=$2 [L,nc]
    RewriteRule ^([0-9]+)/([0-9]+)/([A-Za-z0-9-]+)\.html$ /index.php?id=$1&mo=$2&title=$3 [L,nc]
    RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/([A-Za-z0-9-]+)\.html$ /index.php?id=$1&mo=$2&exp=$3&title=$4 [L,nc]

    It turns out most of the work was required on the web pages themselves. Restructuring all the internal links, to look more SEO friendly. The need for lots of absolute URL's instead of relative ones was a bit of a pain. But I think I have most of those corrected now.

    Add some PHP entry code to rewrite the main entry page, which has specific content.

    More code to have dynamic page titles. That was a nice addition.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles