Sam46 Posted June 8, 2013 Share Posted June 8, 2013 (edited) 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 June 8, 2013 by Sam46 Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/ Share on other sites More sharing options...
trq Posted June 8, 2013 Share Posted June 8, 2013 So your saying, when you type "demo.c/cards" into the address bar "demo.c/cards" does not appear in the address bar. That statement makes no sense at all. Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1434901 Share on other sites More sharing options...
Sam46 Posted June 10, 2013 Author Share Posted June 10, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435064 Share on other sites More sharing options...
Sam46 Posted June 10, 2013 Author Share Posted June 10, 2013 (edited) OK, I notice there something wrong with my thread what happend to my tags? I did enter PHP, Mod_rewrite, URL in the tags input box before I click submit. How come it's not showing? Edited June 10, 2013 by Sam46 Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435074 Share on other sites More sharing options...
kicken Posted June 10, 2013 Share Posted June 10, 2013 (edited) 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 June 10, 2013 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435076 Share on other sites More sharing options...
Sam46 Posted June 10, 2013 Author Share Posted June 10, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435129 Share on other sites More sharing options...
kicken Posted June 10, 2013 Share Posted June 10, 2013 (edited) 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 June 10, 2013 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435142 Share on other sites More sharing options...
Sam46 Posted June 11, 2013 Author Share Posted June 11, 2013 (edited) @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 June 11, 2013 by Sam46 Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435396 Share on other sites More sharing options...
kicken Posted June 12, 2013 Share Posted June 12, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435483 Share on other sites More sharing options...
Sam46 Posted June 12, 2013 Author Share Posted June 12, 2013 @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? Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435497 Share on other sites More sharing options...
kicken Posted June 12, 2013 Share Posted June 12, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435501 Share on other sites More sharing options...
Sam46 Posted June 13, 2013 Author Share Posted June 13, 2013 (edited) @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 June 13, 2013 by Sam46 Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435666 Share on other sites More sharing options...
Sam46 Posted June 13, 2013 Author Share Posted June 13, 2013 @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. Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435740 Share on other sites More sharing options...
Solution DavidAM Posted June 13, 2013 Solution Share Posted June 13, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435795 Share on other sites More sharing options...
Sam46 Posted June 14, 2013 Author Share Posted June 14, 2013 @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 Quote Link to comment https://forums.phpfreaks.com/topic/278931-new-rewrite-url-not-appearing-on-browser/#findComment-1435891 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.