[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.
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
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?
RewriteRule ^/([0-9]+)/([0-9]+)/$ /index.php?id=$1&arc=$2 [r=301,L]
tried with beggining slash?
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
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.
I found a web site ( http://www.generateit.net/mod-rewrite/ ) that creates rewrite code for you. It came up with this;
With this code the friendly URL has to look like this :
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?id=$1&mo=$2 [L]
which it rewrites to :
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.
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.
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
I came up with a set of rewrite rules that pretty much covers my site.
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.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)