Jump to content

Url rewrite problems


Recommended Posts

Url rewrite problems

 

I am having problems with the following url rewrite fragment. 

 

RewriteEngine on

RewriteRule ^profiles/([A-Za-z])$ /profiles/$1/ [R]

RewriteRule ^profiles/([A-Za-z])/$ /profile.php?username=$1

 

I have urls in the following format http://www.site.com/profiles/profile.php?username=peter and I want to rewrite it as http://www.site.com/profiles/peter

 

The url rewrite statement above does not work, the normal url stil appears in the browser.

 

How can I get to achieve what i want ?

 

Cheers

Link to comment
Share on other sites

I've got some new url rewrite patterns

 

Options +FollowSymLinks

RewriteEngine on

RewriteRule profile/(.*)/ profile.php?username=$1

RewriteRule profile/(.*) profile.php?username=$1

 

basically what this should do is convert http://www.site.com/profiles/profile.php?username=FridgeBadger to http://www.site.com/profiles/profile/scoobylol188/

 

am not sure this will work ! any help

Link to comment
Share on other sites

The url rewrite statement above does not work, the normal url stil appears in the browser.

How can I get to achieve what i want ?

 

Yes, it will "still appear". The browser will know absolutely nothing about the rewrite unless you create it then redirect back to the browser for it to make a new request based on an updated URL. HTTP is a "stateless" protocol/transaction which means that each request is posted then, effectively, dropped and "forgotten". The browser keeps no "tab" on any changes being done by the server and remains oblivious to your rewrites. There is no two-way communication between mod_rewrite and the browser other than by posting a response back. Think of it like snail-mail letter exchange.

 

You can rewrite requests but all these do is change what files are accessed by the server unless you redirect [R] back.

 

The problem then is that the browser, although it may now look "pretty" will post back yet another URL which may then need to be rewritten a 2nd time at the back-end to map to the correct file-location. Messy

 

An alternative might be Javascript to twiddle with the URL bar but I can't personally recommend it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.