Manny Posted June 5, 2010 Share Posted June 5, 2010 I'm currently trying to make my site a little more user friendly in terms of URLs.I've had a good look into the mod_rewrite and for the most part, have the URLs working. However, because the original URLs are still accessible, I would like to place a 301 redirect on these. I've searched around the web but still cannot get it working.Below are three examples of rewrites I have set up: RewriteRule ^games/predictionleague/matchday/([0-9]+)$ games/predictionleague/index.php?matchday=$1 [L]RewriteRule ^games/predictionleague/member/([0-9]+)$ games/predictionleague/index.php?member=$1 [L]RewriteRule ^games/predictionleague/([A-Za-z]+)$ games/predictionleague/index.php?action=$1 [L] How would I be able to convert these into 301 redirects without constantly bumping into problems. Link to comment Share on other sites More sharing options...
Synook Posted June 6, 2010 Share Posted June 6, 2010 Just add R=301 to the modifiers, e.g. RewriteRule ^games/predictionleague/matchday/([0-9]+)$ games/predictionleague/index.php?matchday=$1 [L,R=301] Link to comment Share on other sites More sharing options...
Manny Posted June 6, 2010 Author Share Posted June 6, 2010 That works, but the wrong way round:Using the example above: games/predictionleague/matchday/([0-9]+) Redirects to: games/predictionleague/index.php?matchday=$1 I want this the other way round so that the query (?matchday=) is hidden, but it's value remains in the URL. I also believe I have to enter the full URL for the redirect as it enters the full server directory into the address bar. Link to comment Share on other sites More sharing options...
boen_robot Posted June 6, 2010 Share Posted June 6, 2010 Going to another page without the user seeing another URL is a URL rewrite, which I believe is exactly what you were initially doing. Going to another URL and letting the user see it, after making an extra HTTP request is called a redirect, which is what the code Synook showed does.So... which of the two you want again? Link to comment Share on other sites More sharing options...
Manny Posted June 6, 2010 Author Share Posted June 6, 2010 I think I want both:Basically, I want to replace the URLs with the query strings with new URLs.ie: games/predictionleague/matchday/([0-9]+)Instead of:games/predictionleague/index.php?matchday=$1 However, because the content would load through both URLs, if they enter the one with the query string, I want to redirect them to the new URL. Link to comment Share on other sites More sharing options...
boen_robot Posted June 6, 2010 Share Posted June 6, 2010 Have you tried adding that requirement explicitly, i.e. RewriteRule ^games/predictionleague/index.php?matchday=([0-9]+)$ games/predictionleague/matchday/$1 [L,R=301] Link to comment Share on other sites More sharing options...
Manny Posted June 6, 2010 Author Share Posted June 6, 2010 That one doesn't seem to do anything at all.I think I might give it a try using PHP headers. This way seems to cause a few problems. Link to comment Share on other sites More sharing options...
ColdEdge Posted June 7, 2010 Share Posted June 7, 2010 Try this code, if it dosent work remove this part "RewriteBase games/predictionleague" and try again, if dosen't work just post back here. <IfModule mod_rewrite.c> RewriteEngine on RewriteBase games/predictionleague RewriteRule ^games/predictionleague/matchday/([0-9]+) games/predictionleague/index.php?matchday=$1 [L, QSA] <IfModule mod_env.c> SetEnv SEO_SUPPORT 1 </IfModule> </IfModule> The problem is heregames/predictionleague/index.php?matchday=([0-9]+)$ <-- ye that goes 2nd andgames/predictionleague/matchday/$1 <-- goes 1stso ^games/predictionleague/matchday/([0-9]+) games/predictionleague/index.php?matchday=$1 would be correct $1 tells the system to fetch any #int from matchday query. And forces $1 to be displayed after ...../matchday/# Link to comment Share on other sites More sharing options...
Manny Posted June 8, 2010 Author Share Posted June 8, 2010 Thanks for your help ColdEdge, but I've sorted the problem using 301 redirects in PHP.I stumbled across an error whilst trying that out too, but it's sorted now.There is a thread about it here:http://w3schools.invisionzone.com/index.php?showtopic=31797 Link to comment Share on other sites More sharing options...
ColdEdge Posted June 8, 2010 Share Posted June 8, 2010 Did you try my suggestion if script fails to remove RewriteBase games/predictionleague just wondering ^^ Link to comment Share on other sites More sharing options...
Manny Posted June 8, 2010 Author Share Posted June 8, 2010 No, I didn't try it.There will be other rewrites from different directories so my RewriteBase is the root of my site. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.