Forum Moderators: phranque
RewriteRule ^(.+)/(.+)$ index.php?p=$2&l=$1 [L] RewriteCond %{QUERY_STRING} .
RewriteRule ^$ /oddquery? [R=301,L] GET /something[b]?[/b]something HTTP/1.x RewriteCond pattern down to match: [A-Z]{3,9}" \ " /" ([^\?]+)?" \?" ([^\ ]+)" \ " HTTP/" THE_REQUEST server variable. [edited by: g1smd at 9:33 am (utc) on May 3, 2010]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\?]+)?\?([^\ ]+)\ HTTP/ RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\?([^\ ]+)\ HTTP/ RewriteCond %{THE_REQUEST} ^(.*)\?(.*) RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?([^\ ]+)\ HTTP/ [or] example.com/?query, that will be due to the pattern in your RewriteRule, not the one in the RewriteCond. [edited by: Namjies at 10:19 am (utc) on May 3, 2010]
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^(.+)/(.+)$ index.php?p=$2&l=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\?]+)?\?([^\ ]+)\ HTTP/
RewriteCond %{QUERY_STRING} .
RewriteRule ^(.*)$ /oddquery? [R=301,L]
!^(www\.example\.com)?$ which redirects if HTTP_HOST (note capitalisation) is not *exactly* "www.example.com". ^([^/]+)/([^/.]+)$ if those are 'extensionless' URLs (translates to: 'not a slash one or more times, followed by slash, followed by not a period or slash one or more times'). This also avoids using any disk-intensive -f and -d "exists" checks. RewriteRule (.*) http://www.example.com/$1? [R=301,L] here. You'll still pair this with the RewriteCond detecting that QUERY_STRING is present. RewriteRule (.*) /does-not-exist [L] for the rule part. Make sure this rule is now the very last in your list as it is now a rewrite, not a redirect (and again, it will be paired with the existing RewriteCond). Make sure you also add the new line: RewriteCond %{QUERY_STRING} !. to the main content delivery rewrite (so that it only rewrites when there is no query string present).
Options +FollowSymlinks
RewriteEngine on
# Just my way to say "don't try to mess" and to avoid a valid query to return a 200 OK status. I could use redirects to the correct format, but haven't been using the query form since website start, so instead of placing many redirect rules, prefer to return a warning for any queries.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\?]+)?\?([^\ ]+)\ HTTP/
RewriteCond %{QUERY_STRING} .
RewriteRule ^(.*)$ http://www.example.com/noqueryplz? [R=301,L]
# I don't care about the port on this one. Only the page serving is important
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# I added ([^/.]+) with the dot, but my script already returns a 404 error header and load a special notfound page content with a link to homepage if it cannot serve a page correctly with the variables provided.
RewriteRule ^([^/]+)/([^/.]+)$ index.php?p=$2&l=$1 [L]
[edited by: Namjies at 11:14 am (utc) on May 3, 2010]
RewriteCond %{QUERY_STRING} . line is redundant. The previous RewriteCond is only true if there is a query string present. www.example.com[b]:80[/b]/somepage your site returns 200 OK for that URL, and Google would index it as Duplicate Content. You do need to redirect all non-canonical requests.
Options +FollowSymlinks
RewriteEngine on
#
# Externally redirect requests with any query string appended to "noquery" page
RewriteCond %{THE_REQUEST} [i]^[A-Z]+\ /[^?\ ]*\?[^\ ]*\ HTTP/[/i]
RewriteRule [b]^[/b] http://www.example.com/noqueryplz? [R=301,L]
#
# Externally redirect requests for any non-blank non-canonical hostname to canonical hostname
RewriteCond %{HTTP_HOST} [i]!^(www\.example\.com)?$[/i]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# Internally rewrite extensionless single-directory-level-URL requests to script
RewriteRule ^([^/]+)/([^/.]+)$ index.php?p=$2&l=$1 [L]