Jump to content

New Rewrite URL not appearing on browser


Go to solution Solved by DavidAM,

Recommended Posts

Hi

 

I am having issue with a Rewrite URL. The new URL is not appearing on the browser address instead it's the old URL.

 

For example:

 

From this:

 

demo.c/cards.php

 

to this:

 

demo.c/cards

 

When I type this address it will go to the new URL.

 

demo.c/cards

 

I'm been searching the webs to find a way to make the new URL appear on the browser.

 

I also try this:


header(demo.c/cards/");
exit;

 

it didn't work

 

and also try this:

 

<meta HTTP-EQUIV="REFRESH" content="0; url=demo.c/cards/">

 

I also get an error this This problem can sometimes be caused by disabling or refusing to accept cookies.

 

I would appreciate if someone explain to me why the new URL not appearing on the browser.

Edited by Sam46
So your saying, when you type "demo.c/cards" into the address bar "demo.c/cards" does not appear in the address bar.

 

 

Yes, when click on the link it will redirect to the original demo page.

 

For example:

 

This is the original address:

 

http://forums.phpfreaks.com/topic/278931/new/rewrite/url/not/appearing/on/browser/

 

and this is my new rewrite:

 

http://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/

 

The issue is that my new rewrite:

 

http://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/

 

is not appearing on the browser instead it's this:

 

http://forums.phpfreaks.com/topic/278931/new/rewrite/url/not/appearing/on/browser/

 

it's redirecting but the new rewrite is not appearing on the browser.

 

I thought I already explain my situation very clearly.

 

I apologize if I didn't since you don't understand what I said.

 

The rewrite is working but the issue as I mention the new address is not appearing on the browser.

 

Do you I need to used CURL function so the new rewrite will appear on the browser?

Unless you have a RewriteRule to go from the old URL to the new URL using a real redirect (ie the R flag) then the new URL will not appear in the browser. Mod_rewrite changes the URL and does an internal sub-request within apache, the browser never has the slightest idea that the URL has been changed.

 

You need to have the browser make the request using the new URL format in order for it to appear which means

A) Your links should be using this format from the beginning, update any links you have on the site to the new format

B) If there are still old links you want converted, you need to do an actual redirect from the old to the new format using a Location: header, which can be done using the R flag in RewriteRule

 

 

If that is not your issue you may need to explain better because I'm not entirely sure what your trying to say is not working. Posting your rewrite rules may be handy also.

Edited by kicken

Hi

 

This is my code:

      RewriteEngine On
      RewriteRule ^demo/cards-aces$ /demo/cards.php [L,R=301]
Mod_rewrite changes the URL and does an internal sub-request within apache, the browser never has the slightest idea that the URL has been changed.

 

 

What do you mean regarding about browser not knowing the changes and what is a internal sub- request?

 

I think maybe I forgot a step that's why it's not showing the new URL.

 

This is original URL address:

http://www.demo.com/demo/cards.php

This is my new Rewrite:

http://www.demo.com/demo/cards-aces

The new Rewrite which is this:

http://www.demo.com/demo/cards-aces

is not appearing on the browser instead it show my original URL address which is this:

http://www.demo.com/demo/cards.php

When I type the new Rewrite on the browser address bar it will redirect to this:

http://www.demo.com/demo/cards.php

So the rewrite works but it's just that new Rewrite which is this:

http://www.demo.com/demo/cards-aces 

doesn't appear on the browser.

 

Do I need to add couple of lines in the htaccess file in order it to work?

 

or

 

Do I need to used a CURL function so the new URL appear on the browser?

 

RewriteRule ^demo/cards-aces$ /demo/cards.php [L,R=301]

 

Remove the R=301 from there. By including that you are telling the browser to request the rewritten URL which means it will update it's display to show the updated url of /demo/cards.php. By not including the R=301 then apache does an internal sub-request for the updated URL so the browser never knows about it and continues to display the originally requested url of /demo/cards-aces

Edited by kicken

@kicken

 

Thanks for the reply.

 

Remove the R=301 from there. By including that you are telling the browser to request the rewritten URL which means it will update it's display to show the updated url of /demo/cards.php. By not including the R=301 then apache does an internal sub-request for the updated URL so the browser never knows about it and continues to display the originally requested url of /demo/cards-aces

 

 

I took out the R=301 and it didn't work either.

 

I thought maybe it will take time to display the new URL so I left the code intact on my host server for a day to make a transition but it didn't work.

 

This is my updated code:

RewriteEngine On
RewriteRule ^demo/cards-aces$ /demo/cards.php [L]

Do you have any idea why the new URL not appearing on the browser?

Edited by Sam46

Are you typing in the new URL when you load the page? That is what you need to be doing. You might try clearing out your browser cache/history/autocomplete too incase it is remembering the redirect that used to be in place.

@kicken

 

Are you typing in the new URL when you load the page?That is what you need to be doing.

 

 

No, I just type my domain then click on the link which is this:

http://www.demo.com/demo/cards.php

Once I click on that link my browser show this

http://www.demo.com/demo/cards.php

instead it should show the New Rewrite:

http://www.demo.com/demo/cards-aces 
You might try clearing out your browser cache/history/autocomplete too incase it is remembering the redirect that used to be in place.

 

 

Yes, I did that and still it didn't work.

 

So you mean if I keep typing the New Rewrite it will slowly show and change my old url into my New URL?

No, I just type my domain then click on the link which is this:

http://www.demo.com/demo/cards.php

 

Your link needs to point to the new URL: http://www.demo.com/demo/cards-aces.

 

You need to go through your site and update your links to access the proper URL.

 

You seem to be mis-understanding the way mod_rewrite works. It doesn't change your links from the non-friendly url to the friendly url. It converts a friendly url into an unfriendly url. The links you present to the user need to be in the friendly format to start with.

@kicken


 

Your link needs to point to the new URL: http://www.demo.com/demo/cards-aces.

 

 

You mean this for example:

 

From this:

<a href="../demo/cards.php">cards</a>

to this:

<a href="www.demo.com/demo/cards-aces">cards</a>

Is that correct or is that what you meant?

 

You need to go through your site and update your links to access the proper URL.

 

 

OK, I will try that. I'm not sure it will work but I'll try.

 

You seem to be mis-understanding the way mod_rewrite works. It doesn't change your links from the non-friendly url to the friendly url. It converts a friendly url into an unfriendly url. The links you present to the user need to be in the friendly format to start with.

 

 

You are right regarding about mis-understanding the way mod-rewirte works because I don't really fully understand how it works even though I used mod rewrite. I felt by doing mod-rewirte it will change the links so I did got confused.

 

So this consisted unfriendly url:

http://www.demo.com/demo/cards.php

and this is friendly url:

http://www.demo.com/demo/cards-aces.

Is that correct?

 

Maybe you can explain it more in detail so I can grasp on understanding how mod-rewrite really works.

 

I think the code itself works but I need to understand the purpose of it. I read stuff online but never really find the answer like what you just mention.

Edited by Sam46

@kicken
 

 

You need to go through your site and update your links to access the proper URL.

 

 

I try that and it didn't work.

 

So technically the new Rewrite won't appear on the browser at all? It will only appear if I type the New Rewrite on the address bar?

 

If that is the case then I would just mark solve this thread so in the future a person who have similiar issue would know this correct answer.

  • Solution

mod_rewrite is an internal opteration (mostly). Its purpose is to let you provide people with easy to remember and SEO friendly URLs and then direct that url to your script.

 

For instance: I can advertise a url as

SeeMyStuff.com/blue/knit/sweaters

then have mod_rewrite change that to

www.SeeMyStuff.com/products.php?product=sweaters&type=knit&color=blue

then my script (called products.php) can retrieve the parameters ($_GET['product'], etc) to build the page.

 

The fact that you activate mod_rewrite, does NOT automatically change the URLs displayed on your pages from the second format to the first. Whatever you put in the <A href="here"> tag will be the value sent to the browser and sent to the server when the user clicks it. So you have to change all the Anchor tags to the new format (#1 above) before you send it to the user (i.e. in your code) if you want them shown in the new format. Of course, the second format will still work from links or the address bar as well.

 

When used in this way, the URL in the address bar DOES NOT CHANGE. If the user clicks a link containing either of the urls shown above, that is what they will see in the address bar, regardless of how you rewrite it.

@DavidAM

 

The fact that you activate mod_rewrite, does NOT automatically change the URLs displayed on your pages from the second format to the first. Whatever you put in the <A href="here"> tag will be the value sent to the browser and sent to the server when the user clicks it. So you have to change all the Anchor tags to the new format (#1 above) before you send it to the user (i.e. in your code) if you want them shown in the new format. Of course, the second format will still work from links or the address bar as well.

When used in this way, the URL in the address bar DOES NOT CHANGE. If the user clicks a link containing either of the urls shown above, that is what they will see in the address bar, regardless of how you rewrite it.

 

 

The explanation you provided is very detail and I think I understand more about the mod_rewrite and how it works. Thank You.

 

@kicken

@DavidAM

 

I want to thank both of you taking time to explain mod_write and how it function and why.

 

Thanks.

 

Sam

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.