Jump to content

.htaccess


Manny

Recommended Posts

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

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

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...