1

I've got:

RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]

Which points page/([^/\.]+)/? to index.php?page=$1.

When I go to page/([^/\.]+)/, I don't want to see index.php (which is achieved from the above)

For the reverse, when I go to index.php, I want to see a visible 301 redirection to page/([^/\.]+)/.

How do I do this without causing an infinite loop... or do I only rely on canonical tags?

Update:

I got it happening in one direction (new to old), but not the other (Old to new)

RewriteRule ^([^/\.]+)-yum/?$ yum/?x=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)-yum/?$ yum/?x=$2&y=$1 [L]
4

2 回答 2

0

You need to do a check against the %{THE_REQUEST} variable so that you are rewriting only when the actual request is for the index.php file:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?page=([^&]+)([^\ ]*)
RewriteRule ^/?index\.php$ /page/%1/?%2 [L,R=301]

So if a browser requests http://yourdomain.com/index.php?page=qwe&someother=var

It should get redirected to: http://yourdomain.com/page/qwe/?someother=var

于 2012-07-26T17:34:23.903 回答
0

Full solution here:

RewriteCond %{QUERY_STRING} Variable=([A-Za-z]+)$
RewriteRule OldURL/$ /NewURL/%1? [L,R=301]
RewriteRule ^NewUrl/([^/\.]+)$ MappedNewLocationFolder/?Variable=$1 [L]

1st Line: Check (the name and number of) parameters are as expected

2nd Line: Check base path of parameter(s), which is OldURL is correct and 301 to NewUrl

3rd Line: Map NewUrl to actual location where file sits (not shown in browser)

(The question mark right at the end of 2nd line strips out the variables from appending to the NewUrl)

于 2012-08-01T15:55:07.120 回答