开发者

htaccess redirect based on a block of URL parameters

开发者 https://www.devze.com 2023-03-18 10:04 出处:网络
I\'m trying to do a htaccess redirect based on a parameter in de URL. Sounds simple but my problem is this: a block of parameters I want to go to the left and the rest to the right.

I'm trying to do a htaccess redirect based on a parameter in de URL. Sounds simple but my problem is this: a block of parameters I want to go to the left and the rest to the right.

The example:

Current URL (not existent): http: www.schedjoules.com/开发者_运维知识库102657832.html Desired URL: http: www.schedjoules.com/us/102657832.html

Everyhting between 102633352 and 102657832 I want to direct to www.schedjoules.com/us/ and everything else to www.schedjoules.com/en/

The best rewrite I can think of is RewriteRule ^/([102633352-102657832])\.html$ http://www.schedjoules.com/us/$1\.html [R=301,L]

but it is doesn't work (500 error). I have read half the internet but can't find a solution. Is there a way to redirect by a block of parameters?

Rutger


Your rule is completely wrong: [102633352-102657832]

The square brackets mean a character class - matches one of the characters. You have repeated the same characters multiple times (e.g. 1, 0 etc) + you have a range character - describing invalid range (can be from lower to higher 1-2 not 2-1).

In any case -- these rules will do the job:

RewriteCond $1 >102633351
RewriteCond $1 <102657833
RewriteRule ^(\d+)\.html$ http://www.schedjoules.com/us/$1\.html [R=301,L]
RewriteRule ^(\d+)\.html$ http://www.schedjoules.com/en/$1\.html [R=301,L]
  1. Lexicographical comparison was used (< and >)

  2. Because comparison is not numeric but rather by character, the numbers have been changed (-1/+1 accordingly) otherwise the edge numbers would fail.

  3. These rules will redirect files within a range to /us/ subfolder and ALL OTHER NUMBERS to /en/.

0

精彩评论

暂无评论...
验证码 换一张
取 消