Forum Moderators: phranque
[edited by: phranque at 4:02 pm (utc) on Mar 28, 2014]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]
your Substitution string for external redirects should always begin with the canonical protocol and hostname.
your Substitution string for external redirects should always begin with the canonical protocol and hostname.
Why's that, phranque? If he's rewriting to the same domain and protocol with a 301 redirect, why is it preferred?
# externally redirect some old path to a new path
RewriteRule old/path /new/path [R=301, L]
# after all the specific redirects above, do a general hostname canonicalization redirect
RewriteCond %{HTTP_HOST} !^(example\.com)?$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] when we refer to QSA, this means "query string append". It means that if your original link has a query string, like:
index.php?variable=something
then the redirect will keep the ?variable=something at the end of the new link.
When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.
Consider the following rule:
RewriteRule /pages/(.+) /page.php?page=$1 [QSA]
With the [QSA] flag, a request for /pages/123?one=two will be mapped to /page.php?page=123&one=two. Without the [QSA] flag, that same request will be mapped to /page.php?page=123 - that is, the existing query string will be discarded.
http://www.example.com/?pageid=45&pagename=some-page or http://www.example.com/index.php?pageid=45&pagename=some-page http://www.example.com/p45-some-page RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?pageid=([0-9]+)&pagename=([a-z0-9-]+)\ HTTP/
RewriteRule ^(index\.php)?$ http://www.example.com/p%1-%2? [R=301,L] http://www.example.com/p45-some-page?pageid=45&pagename=some-page http://www.example.com/p45-some-page http://www.example.com/p45-some-page?sort_order=reverse RewriteRule ^p([0-9]+)-(.*) /index.php?pageid=$1&pagename=$2 [L,QSA] sort_order parameter is also passed through to the index.php script.