Forum Moderators: phranque
[edited by: phranque at 9:31 am (utc) on Sep 24, 2013]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]
What I am trying to do is redirect
...
I have tried the following test code:
The only issue is that even http://legacy_web/info/index.php?page=23 redirects ...
RewriteRule (.*) http://www.example.com? [R=301,L]
The only issue is that even http://example.com/info/index.php?page=23 redirects to www.example.com
similar to the policies above.
RewriteCond %{THE_REQUEST} (\?|&)page=23\b
your test code doesn't address any of the redirects you described.
RewriteCond page=23$
RewriteEngine on
RewriteRule ^policies/$ http://www.example1.com/news? [R=301,L]
RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php$ http://www.examplee2.com? [R=301,L]
RewriteRule ^policies/index\.php$ http://www.exampleee3.com? [R=301,L]
RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^careers/index\.php$ http://www.exampleeee4.com? [R=301,L]
RewriteCond %{QUERY_STRING} page=25$
RewriteRule ^careers/index\.php$ http://www.exampleeeee5.com? [R=301,L]
when I use RewriteCond without the variable (parentheses) it does not work
%{QUERY_STRING} RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php$ http://www.examplee2.com? [R=301,L] RewriteRule ^policies/index\.php$ RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php$ http://www.examplee2.com? [R=301,L] @phranque
I'm sorry, I don't understand your comment.your test code doesn't address any of the redirects you described.
What I am trying to do is redirect
example.com/company/index.php to example.com/about_us
example.com/company/index.php?page=12 to example.com/about_us/history
example.com/info/index.php?page=12 to example.com/contact_us
my understanding is that "^" denotes the beginning and "$" denotes the end.
so in RewriteRule ^policies/index\.php$
it looks for anything that has "policies/index.php"
this will include
www.example.com/policies/index.php
www.example.com/policies/index.php?page=12345
www.example.com/policies/subfolder/index.php
Is this correct?
If it is, then isn't this code
RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php$ [examplee2.com?...] [R=301,L]
saying first look at anything that ends in "page=23" and then look at
2. anything that ends in "policies/index.php"
which is a contradictory argument as a it can either end with a .php or a .php?page=23 but not both.
or is that code saying first look at "policies/index.php" and then check for any queries that match 'page=23'
Do I need to add the '$" in the second line on the RewriteRule?
RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php$ ... www.example.com/policies/index.php?page=23 www.example.com/policies/index.php?thispage=23 (^|&)page=23 www.example.com/policies/index.php?thisparam=thatvalue&page=23 www.example.com/policies/index.php?page=23&otherparam=othervalue (&|$) to allow for additional parameters. RewriteCond %{QUERY_STRING} page=23$ RewriteCond %{QUERY_STRING} (^|&)page=23(&|$) RewriteRule pattern is evaluated first. Only if it is an exact match will the RewriteCond pattern(s) be assessed.
I have not used "&" in my code.
Isn't this code
RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php$ http://www.example.com? [R=301,L]
saying first look at anything that ends in "page=23" and then look at
2. anything that ends in "policies/index.php"
RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php$ http://www.examplee2.com? [R=301,L]
RewriteRule ^policies/index\.php http://www.google.com? [R=301,L]
RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php http://www.theage.com.au? [R=301,L] RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php http://www.theage.com.au? [R=301,L]
RewriteRule ^policies/index\.php http://www.google.com? [R=301,L] page=25$
and
(^|&)page=(23|24|11)(&|$)
page=25$ (^|&)page=25$ (^|&)name=value($|&) Options +FollowSymlinks
RewriteEngine on
#redirect any query that contains either page=16 or page=25 in the url path, to "team" directory
RewriteCond %{QUERY_STRING} (^|&)page=(16|25)(&|$)
RewriteRule ^investors/index\.php$ /aboutus/companyprofile/team? [R=301,L]
#redirect any query that contains page=22 in the url path, to "press" directory
RewriteCond %{QUERY_STRING} (^|&)page=22(&|$)
RewriteRule ^investors/index\.php$ /aboutus/companyprofile/press? [R=301,L]
#redirect anything in investors directory to "companyprofile" directory
RewriteRule ^investors/(.*)$ /aboutus/companyprofile? [R=301,L]
#redirect anything in sitemaps directory to "root"
RewriteRule ^sitemap/(.*)$ http://www.example.com? [R=301,L]
Redirect 301 /induction.html /training/induction
Redirect 301 /corpinduction.html /training/induction
#redirect anything in assets>pdfs directory to "resources>doucments directory"
#i.e. redirect www.example.com/assets/pdf/test.pdf to http://www.example.com/resources/documents
RewriteRule ^/assets/pdf/(.*)$ /resources/documents? [R=301,L]
#redirect http://example.com/index.html to http://www.example.com
RewriteRule ^index\.html$ / [NC, R=301,L]
#redirect anything that is not www.example.com to www.example.com
#i.e. redirect http//example.com or example.com
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] Redirect 301
^investors/index\.php$ ^investors/(index\.php)?$ Redirect 301 ... ... RewriteRule ... ... [R=301,L] http://www.example.com? http://www.example.com/? !^www\.example\.com [NC] !^(www\.example\.com)?$ ^/assets/pdf/(.*)$ ^assets/pdf/(.*) Patterns like
^investors/index\.php$
are better off expressed as
^investors/(index\.php)?$
so that both URLs redirect.
Patterns like
^investors/index\.php$
are better off expressed as
^investors/(index\.php)?$
so that both URLs redirect.
Change rule target from
http://www.example.com?
to
http://www.example.com/?
as the trailing slash is important.
directories and folders
RewriteRule ^investors/(.*)$ /aboutus/companyprofile? [R=301,L] perhaps ^investors/ with no closing anchors means
everything after investors/
e.g. investors/mymoney.php
investors/index.php
Redirect 301 ^investors/ http://www.example.com/litigants/ RewriteRule ^investors/ http://www.example.com/litigants/ [R=301,L] RewriteRule ^investors/(.*) http://www.example.com/litigants/$1 [R=301,L]
^investors/index\.php$ ^investors/(index\.php)?$ RewriteCond %{QUERY_STRING} (^|&)page=22(&|$) example.com/investors/index.php?page=22 example.com/investors/?page=22 example.com/aboutus/companyprofile/press example.com/aboutus/companyprofile example.com/investors
Options +FollowSymlinks
RewriteEngine on
#redirect any query that contains either page=16 or page=25 in the url path, to "team" directory
RewriteCond %{QUERY_STRING} (^|&)page=(16|25)(&|$)
RewriteRule ^investors/index\.php$ http://www.example.com.au/aboutus/companyprofile/team? [R=301,L]
#redirect any query that contains page=22 in the url path, to "press" directory
RewriteCond %{QUERY_STRING} (^|&)page=22(&|$)
RewriteRule ^investors/index\.php$ http://www.example.com.au/aboutus/companyprofile/press? [R=301,L]
#redirect anything in investors directory to "companyprofile" directory
RewriteRule ^investors/ http://www.example.com.au/aboutus/companyprofile? [R=301,L]
#redirect anything in sitemaps directory to "root"
RewriteRule ^sitemap/ http://www.example.com? [R=301,L]
RewriteRule ^induction.html http://www.example.com.au/training/induction [R=301,L]
RewriteRule ^corpinduction.html http://www.example.com.au/training/induction [R=301,L]
#redirect anything in assets>pdfs directory to "resources>doucments directory"
#i.e. redirect www.example.com.au/assets/pdf/test.pdf to http://www.example.com.au/resources/documents
RewriteRule ^assets/pdf/ http://www.example.com.au/resources/documents? [R=301,L]
#redirect http://example.com.au/index.html to http://www.example.com.au
RewriteRule ^index\.html$ / [NC, R=301,L]
#redirect anything that is not www.example.com.au to www.example.com.au
#i.e. redirect http//example.com.au or example.com.au
RewriteCond %{HTTP_HOST} !^www\.example\.com\.au [NC]
RewriteRule ^(.*)$ http://www.example.com.au/$1 [L,R=301] On your old site, requests for
example.com/investors/index.php?page=22
and
example.com/investors/?page=22
should have displayed the same content.
RewriteCond %{QUERY_STRING} (^|&)page=22(&|$)
RewriteRule ^investors/index\.php$ http://www.example.com.au/aboutus/companyprofile/press? [R=301,L] RewriteRule ^investors/ http://www.example.com.au/aboutus/companyprofile? [R=301,L]