Forum Moderators: phranque
[edited by: jdMorgan at 2:47 pm (utc) on Dec. 16, 2009]
[edit reason] No URLs, please. See Terms of Service and Charter. [/edit]
DirectoryIndex intro.phpRewriteEngine on
RewriteBase /
#begin adding an ending slash for (intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/language/(en¦sp)
RewriteRule ^(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/language/(sp¦en)$ http://www.example.com/$1/language/$2/? [L,R=301]
#end adding an ending slash for (intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/language/(en¦sp)
#Begin delete old dynamic link from google index with a redirect R = 301. Si solo se pone R, se pone 302 por defecto
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^language=sp$
RewriteRule .* http://www.example.com/? [L,R=301]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^language=en$
RewriteRule .* http://www.example.com/intro/language/en/? [L,R=301]
#End delete old dynamic link from google index with a redirect R = 301. Si solo se pone R, se pone 302 por defecto
#Begin Loop Stopping Code
RewriteCond %{REQUEST_URI} ^/(stats/¦missing\.html¦failed_auth\.html¦error/).* [NC]
RewriteRule .* - [L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
#End Loop Stopping Code
#Begin replacing www.example.com/home.php with www.example.com/home/language/sp/ to avoid aliases which is bad for SEO. To make this work I had to place the code for avoiding infinite loops
RewriteRule (intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)\.php$ $1 [NC,R=301]
#End replacing www.example.com/home.php with www.example.com/home/language/sp/ to avoid aliases which is bad for SEO. To make this work I had to place the code for avoiding infinite loops
#Begin remove the .php from www.example.com/home.php/.*
RewriteCond %{REQUEST_URI} !^/(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)\.php/language/en/? [NC]
RewriteCond %{QUERY_STRING} !^language=en$
RewriteCond %{REQUEST_URI} ^/(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)\.php/.*$ [NC]
RewriteRule .* http://www.example.com/%1/language/sp/? [L,R=301,NC]
RewriteCond %{REQUEST_URI} !^/(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)\.php/language/en/? [NC]
RewriteCond %{QUERY_STRING} ^language=en$
RewriteCond %{REQUEST_URI} ^/(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)\.php/.*$ [NC]
RewriteRule .* http://www.example.com/%1/language/en/? [L,R=301,NC]
#End remove the .php from www.example.com/home.php/.*
#Begin remove the .php from www.example.com/home.php/language/en/
RewriteCond %{REQUEST_URI} (intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)\.php/language/en/?$ [NC]
RewriteRule .* http://www.example.com/%1/language/en/? [L,R=301,NC]
#End remove the .php from www.example.com/home.php/language/en/
#Begin redirect intro/language/sp e intro/language e intro/ e intro a www.example.com
RewriteCond %{REQUEST_URI} (/intro/.*)¦(/intro)[NC]
RewriteCond %{REQUEST_URI} !/intro/language/en/?$[NC]
RewriteRule .* http://www.example.com/? [L,R=301,NC]
#End redirect intro/language/sp e intro/language e intro/ e intro a www.example.com
#begin redirect example.com/home into example.com/home/language/sp
RewriteCond %{REQUEST_URI} /(home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/?$ [NC]
RewriteCond %{QUERY_STRING} !^language=en$
RewriteRule .* http://www.example.com/%1/language/sp/? [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^language=en$
RewriteCond %{REQUEST_URI} /(home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/?$ [NC]
RewriteRule .* http://www.example.com/%1/language/en/? [L,NC,R=301]
#end redirect example.com/home into example.com/home/language/sp
#remove the language part of the end of the url when this language is not available and therefore, not accepted
RewriteCond %{REQUEST_URI} (intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/language/(.*)$ [NC]
RewriteCond %{REQUEST_URI} !(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/language/sp/?$ [NC]
RewriteCond %{REQUEST_URI} !(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/language/en/?$ [NC]
RewriteRule .* http://www.example.com/%1/ [L,R=301,NC]
#remove the language part of the end of the url when this language is not available and therefore, not accepted
#begin add www to the url so that the url name is cannonical. In this case we must not remove the query string
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#end add www to the url so that the url name is cannonical. In this case we must not remove the query string
#begin convert dynamic urls into static urls
RewriteRule ^(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/language/([^/]*) $1.php?language=$2 [L,NC]
RewriteRule ^(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/language/([^/]+)/ $1.php?language=$2 [L,NC]
#RewriteRule ^(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound) $1.php #this line is not needed any more since we are adding slash at the end of the url in case it is missing
RewriteRule ^(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/ $1.php [NC]
#end begin convert dynamic urls into static urls
#begin adding an ending slash for those url ending in strings which are folders in case the endind slash is missing
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_URI} !(.*)/$[NC]
RewriteRule ^(.*)$ %{REQUEST_URI}/ [L,NC] #This line adds a slash to the end of the url
#end adding an ending slash for those url ending in strings which are folders in case the endind slash is missing
#begin removing the part of the end of the url which is not needed
#Sees whether the requested URI ends in that pattern
RewriteCond %{REQUEST_URI} (intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/(.+)$ [NC]
#Rewrite the URI with the URL specified
RewriteRule .* http://www.example.com/%1/ [L,R=301,NC]
#end removing the part of the end of the url which is not needed
#begin removing the not needed slash after the first slash following example.com
RewriteCond %{REQUEST_URI} /(/+)$[NC]
RewriteRule .* http://www.example.com/ [L,R=301,NC]
#begin removing the not needed slash after the first slash following example.com
#begin redirect to custom error page
ErrorDocument 404 /notfound.php
#end redirect to custom error page
[edited by: jdMorgan at 5:37 pm (utc) on Dec. 16, 2009]
[edit reason] Deleted commented-out rules to shorten the post. [/edit]
For example, these two rules
#Begin delete old dynamic link from google index with a redirect R = 301. Si solo se pone R, se pone 302 por defecto
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^language=sp$
RewriteRule .* http://www.example.com/? [L,R=301]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^language=en$
RewriteRule .* http://www.example.com/intro/language/en/? [L,R=301]
#End delete old dynamic link from google index
#Begin delete old dynamic link from google index with a redirect R = 301. Si solo se pone R, se pone 302 por defecto
RewriteCond %{QUERY_STRING}>intro/language/en/ ^language=(sp>.+¦en>(.+))$
RewriteRule ^$ http://www.example.com/%2? [L,R=301]
#End delete old dynamic link from google index
As another example, these two rules
#begin convert dynamic urls into static urls
RewriteRule ^(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/language/([^/]*) $1.php?language=$2 [L,NC]
RewriteRule ^(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/language/([^/]+)/ $1.php?language=$2 [L,NC]
#begin convert dynamic urls into static urls
RewriteRule ^(intro¦home¦services¦advice¦webdesign¦clases¦contact¦writeEmail¦aboutme¦notfound)/language/([^/]*[b])/?[/b]$ $1.php?language=$2 [L,NC]
And in fact, if the intent was *not* to require that the requested URL end with that slash or at the character preceding that slash then you only need your first rule, since that pattern is not end-anchored and therefore would accept *anything* following the URL-path specified by the pattern.
You've also got internal rewrite [L] rules preceding external redirect [R=301,L] rules, which is almost certain to cause a disaster.
---
It's also not clear which rule you added that 'broke' your WordPress, or what the URL-path to your WordPress pages and files might be. We need to know these things.
If you can narrow-down which rule it is that causes your WP to fail, we can help fix that rule. However, once that is done, this code needs to be re-written. I suspect you could reduce its execution time to less than one quarter of what it requires now... This is meant as earnest advice, and not as criticism.
Jim
RewriteCond %{QUERY_STRING}>intro/language/en/ ^language=(sp>.+¦en>(.+))$
RewriteRule ^$ http://www.example.com/%2? [L,R=301]
I do not get it. Moreover, when I just tested, it does not work the same as the other lines. So, should I guess there might be something wrong with these two lines?
I would just put
RewriteCond %{QUERY_STRING} ^language=(sp¦en)$
RewriteRule ^$ http://www.example.com/intro/language/%1? [L,R=301]
Is that what you meant?
Thanks
RewriteCond %{QUERY_STRING}>intro/language/en/ ^language=(sp>.+¦en>(.+))$
RewriteRule ^$ http://www.example.com/%2? [L,R=301]
It's just a short way of combining your two rules. Note that "%2" will be empty for Spanish and contain the "/intro..." path for English.
The ">" implies concatenation, but in fact has no special meaning and only serves to demarcate the two 'pieces' of the input string so that the pattern can tell where the first ends and the second begins.
If it didn't work, then make sure that you replaced the broken pipe "¦" character with a solid pipe; Posting on this forum modifies the pipe characters.
Jim
The ">" implies concatenation, but in fact has no special meaning...
I use it as a 'visual cue' and as stated, to demarcate the 'boundary' between the concatentated values so that the regular-expressions pattern can 'exactly match' *both* pieces, and won't be 'fooled' if one variable-value or fixed string-part contains part of the expected value for the other variable or string.
This isn't really a mod_rewrite subject, it's a regular-expressions topic. The only fact you need to take from the mod_rewrite documentation is that you can put either variables or fixed strings on the 'left side' of a RewriteCond, and you can put multiple variables and strings there, and then test the result of the concatenation of these variable-values and fixed strings using a regular-expressions pattern on the right side of the RewriteCond.
It's useful for building 'lookup tables' and for rolling-up multiple rules into single rules as in the example here.
Jim