homepage Welcome to WebmasterWorld Guest from 54.161.240.10
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

This 38 message thread spans 2 pages: 38 ( [1] 2 > >     
.htaccess redirect singly url query strings
Best way to redirect individual, single source urls to specific target urls
Force10x




msg:4612230
 7:38 am on Sep 24, 2013 (gmt 0)

Hi All,

I am new to this and am struggling past two days.

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

I have tried the following test code:

RewriteEngine on
RewriteRule ^policies/$ http://www.example.com/news? [R=301,L]

(http://legacy_web/about_us/ to http://www.example.com/news)


RewriteCond %{QUERY_STRING} page=23$
RewriteRule (.*) http://www.example.com? [R=301,L]

(http://legacy_web/about_us/index.php?page=23 to http://www.example.com)


RewriteRule ^policies/index\.php$ http://www.example.com? [R=301,L]

(http://legacy_web/about_us/index.php to http://www.example.com)


These work. The only issue is that even http://legacy_web/info/index.php?page=23 redirects to www.example.com
similar to the policies above.

A shove in the right direction much appreciated.

Thank you for your time and help

[edited by: phranque at 9:31 am (utc) on Sep 24, 2013]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]

 

phranque




msg:4612254
 9:39 am on Sep 24, 2013 (gmt 0)

What I am trying to do is redirect
...
I have tried the following test code:

your test code doesn't address any of the redirects you described.


The only issue is that even http://legacy_web/info/index.php?page=23 redirects ...

the Pattern of your RewriteRule needs to be more specific here:
RewriteRule (.*) http://www.example.com? [R=301,L]

lucy24




msg:4612394
 7:37 pm on Sep 24, 2013 (gmt 0)

The only issue is that even http://example.com/info/index.php?page=23 redirects to www.example.com
similar to the policies above.

Chorus:
I really hate this damned machine
I wish that they would sell it
It never does quite what I want
But only what I tell it.


The RewriteRule is doing exactly what you told it to do: take any request of any kind
.*
so long as it's got the "page=23" parameter, and redirect. But normally you would never do this. The body of the rule gives the name of the page. The RewriteCond then looks at additional information-- here the query string-- to narrow it down still further.

Incidentally, you don't need to capture the request (parentheses) since you're not reusing it.

You've done one thing exactly right so make sure you keep it: The target of each rule ends in ? meaning get rid of the whole query string.

Do you have a second set of RewriteRules further along to rewrite (not redirect) requests for /news and /history and so on to the appropriate source? You then need to have a second RewriteCond on the redirects, looking at {THE_REQUEST}. In fact you can combine them into a single condition so long as you don't put anchors in the wrong places:

RewriteCond %{THE_REQUEST} (\?|&)page=23\b
Force10x




msg:4612464
 12:16 am on Sep 25, 2013 (gmt 0)

Thank you for making time to reply to my queries.

I have not done this before, so appreciate your patience and apologies for "inappropriate" questions.

@phranque
I'm sorry, I don't understand your comment.
your test code doesn't address any of the redirects you described.

My understanding is that RewriteRule is one way to redirect especially when there are queries involved.

From what I know, a simple
Redirect 301 /path/file.html?id=10 http://www.example.com will not work as the query will be ignored

@lucy24
Thank you. Your comments have helped me understand better.
when I use RewriteCond without the variable (parentheses) it does not work :(
RewriteCond page=23$

I got the following code to work based on the above feedback


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]


lucy24




msg:4612473
 1:38 am on Sep 25, 2013 (gmt 0)

when I use RewriteCond without the variable (parentheses) it does not work

Whoops! There's a second reason for using parentheses, and that's what we're dealing with here.

(\?|&)

Those aren't capturing parentheses. That is, they could be, but they're not needed for that job. They are needed as grouping parentheses. Here they're combining two different options... which I now realize can pefectly well go in brackets instead:

[?&]

That only works if you're looking at THE_REQUEST without anchors. If your RewriteCond is instead looking at the QUERY_STRING, you need parentheses
(^|&)
because you're separating two different symbols: either the anchor ^ or the literal character &.

What happens to requests after they've been redirected to
www.example.com/info
or similar? Technically you could have a file named "info" without extension, but it doesn't seem awfully likely. Is there rewriting somewhere else?

Second issue: If you're redirecting a whole bunch of different pages distinguished only by the query string

index.php?page=23
index.php?page=24
index.php?page=25

and so on, you may be better off rewriting in htaccess to a php page that looks up the numbers and issues the appropriate redirect. You might even use the same php code in both directions.

Force10x




msg:4612492
 4:25 am on Sep 25, 2013 (gmt 0)

Wow. This is getting a lot more complicated then I imagined.

@Lucy24 Thanks for replying

I was referring to the parentheses in
%{QUERY_STRING}

Also, I have not used "&" in my code.

To answer your questions
The legacy website was built using php over 10 years ago. The organisation has now moved to a Java/JSP based CMS. Hence the need for 301 redirects

With the new CMS, pages do not have an extension because it is using some sort of an "alias" to point to pages within the CMS.

Now, with the working code I posted above, I am a bit confused.
RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php$ http://www.examplee2.com? [R=301,L]


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$ http://www.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?

Thank you and apologies for this long winded post.

phranque




msg:4612532
 8:21 am on Sep 25, 2013 (gmt 0)

@phranque
I'm sorry, I don't understand your comment.
your test code doesn't address any of the redirects you described.

i was referring to these redirects in your problem statement:
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"

any path that is exactly "policies/index.php" - no more or less.

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?

the path with the subfolder won't match the Pattern.

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'

more precisely stated, match a path that is exactly "policies/index.php" and match a query string that ends with "page=23".

Do I need to add the '$" in the second line on the RewriteRule?

which one was that?

g1smd




msg:4612534
 8:33 am on Sep 25, 2013 (gmt 0)

RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php$ ...


will redirect these requests

www.example.com/policies/index.php?page=23
- as expected

www.example.com/policies/index.php?thispage=23
- because there's no start anchor like
(^|&)page=23

www.example.com/policies/index.php?thisparam=thatvalue&page=23

but will NOT redirect
www.example.com/policies/index.php?page=23&otherparam=othervalue
- because you used the $ closing anchor when you should have used
(&|$) to allow for additional parameters.

Replace
RewriteCond %{QUERY_STRING} page=23$
with
RewriteCond %{QUERY_STRING} (^|&)page=23(&|$)


One important note about rule processing. The
RewriteRule pattern is evaluated first. Only if it is an exact match will the RewriteCond pattern(s) be assessed.
lucy24




msg:4612554
 11:05 am on Sep 25, 2013 (gmt 0)

I have not used "&" in my code.

Do you mean that your query string only ever contains one parameter? It's still a good habit to allow for all possibilities. You never know when some other parameter will attach itself to your URL.

Within the query string,
(^|&)foobar
means
"'foobar' is the very first item in the query string (^ beginning anchor) OR it's the beginning of some subsequent query (literal character & used to separate items in a query string)"

while
foobar($|&)
means
"'foobar' is the very last item in the query string ($ ending anchor) OR it's the end of one query, followed by another one (literal character & used to separate items in a query string)"

The parentheses don't capture anything, but they're essential for grouping.

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"

No. mod_rewrite doesn't even look at the conditions unless the body of the rule matches. Two steps forward, one back.

The RewriteRule itself looks only at the "path" of the URL. Other aspects of the request-- protocol, hostname, query string, and also any other information like the visitor's IP or browser, or the referer-- go into Conditions.

At each point, the anchors apply to whatever string the current condition is looking at.

Say you ask for
http://www.example.com/policies/index.php?page=1&item=2&widget=42

In the body of a RewriteRule, this is expressed as
^policies/index\.php$

In a RewriteCond looking at the query string, it's
^page=1&item=2&widget=42$

In a RewriteCond looking at the host, it's
^www\.example\.com$

and so on.

Force10x




msg:4612756
 11:26 pm on Sep 25, 2013 (gmt 0)

Thank you phranque, g1smd and lucy24

I understand it a lot better now.

With respect to the "$" in the RewriteRule (second line) below
RewriteCond %{QUERY_STRING} page=23$
RewriteRule ^policies/index\.php$ http://www.examplee2.com? [R=301,L]


Is it better not to add the "$" after index\.php


Once again thank you all.
This is very helpful.

phranque




msg:4612763
 12:29 am on Sep 26, 2013 (gmt 0)

the query string is not part of the path.
if there is nothing after "index.php" in the path then the end anchor ($) is appropriate.

lucy24




msg:4612769
 12:57 am on Sep 26, 2013 (gmt 0)

Is it better not to add the "$" after index\.php

It depends, first, on whether you ever get malformed requests for

www.example.com/index.php234
or
www.example.com/index.php/more-garbage-here

and, second, on whether you want to be helpful to these requests.

Force10x




msg:4613030
 12:03 am on Sep 27, 2013 (gmt 0)

Thank you :-)

I just realised that the order of the code affects the way it is executed.

this
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]




is different from this
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]



Edited: Code formatting

g1smd




msg:4613042
 12:40 am on Sep 27, 2013 (gmt 0)

Yep. Order is very important.

General order:
-Blocks
-Redirects
-Rewrites

Within each group:
-most specific first,
-most general last.

Force10x




msg:4613065
 2:40 am on Sep 27, 2013 (gmt 0)

That helps

Got this bit working as well.

RewriteCond %{QUERY_STRING} page=(23|24|11)$
RewriteRule ^policies/index\.php$ http://www.example1.com/folder1? [R=301,L]


RewriteCond %{QUERY_STRING} page=25$
RewriteRule ^policies/index\.php$ http://www.example.com/elsehwere? [R=301,L]

phranque




msg:4613069
 4:16 am on Sep 27, 2013 (gmt 0)

http://www.example1.com/folder1


if folder1 is actually a directory you want the trailing slash in that Substitution string.

g1smd




msg:4613107
 8:30 am on Sep 27, 2013 (gmt 0)

Change
page=(23|24|11)$
to
(^|&)page=(23|24|11)(&|$)
or even to
(^|&)page=(2[34]|11)(&|$)

Add those anchors to the other rule too.

Force10x




msg:4613664
 11:31 pm on Sep 29, 2013 (gmt 0)

I am trying to understand the difference between

page=25$

and

(^|&)page=(23|24|11)(&|$)

Will page=25$ match only
folder1/index.php?page=5
which is an exact match

Whereas this pattern matches (^|&)page=(23|24|11)(&|$)

folder1/index.php?firstvar=111&page=23&anothervar=48

lucy24




msg:4613691
 2:53 am on Sep 30, 2013 (gmt 0)

page=25$

and

(^|&)page=(23|24|11)(&|$)

A while back, there was a superb post from someone whose real-life, non-hypothetical parameters contained other parameter names within themselves.

on=1
region=12

Needless to say I can't find it now, but it was amazingly useful.

page=25$
means the last thing in the query string is "page=25":
page=25
rampage=25
stoppage=25
and so on.

The value can't be 250 or 25z or 250000 -- but there also can't be any other paremeters.

(^|&)page=25$
means the element "page" is the complete name of this parameter. There may or may not be earlier parameters in the same query string.

When you need to separate out one element of a query string, it looks like this:

(^|&)name=value($|&)

You have to use that complicated business with parentheses and pipes because & is a literal character while ^ and $ are anchors. "Query String" means the whole thing; mod_rewrite can't see individual parameters.

If you say &) in the Forums, you have to either click 'Disable Graphic Smileys' or put it inside Code markup. The & turns into & which in turn triggers the ;)

Force10x




msg:4613703
 4:15 am on Sep 30, 2013 (gmt 0)

Thank you very much. That explanation was so simple and easy to understand.

Force10x




msg:4613707
 6:24 am on Sep 30, 2013 (gmt 0)

This is my final code based on all the help I got on this thread

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]


Edited to format code

lucy24




msg:4613724
 8:11 am on Sep 30, 2013 (gmt 0)

Redirect 301

AAAACCCK!

Once you have RewriteRules, you must find any rules using mod_alias (Redirect by that name) and translate them to mod_rewrite (RewriteRule with [R] flag). This is easy to do.

We keep telling you to put a blank line after each RewriteRule. But the opposite is important too: don't leave blank lines between a RewriteCond (or group of RewriteConds) and the RewriteRule it belongs to.

Empty lines have no syntactic meaning in htaccess. (They do in robots.txt.) They are purely for your own benefit, to help you stay organized and remember what goes with what.

g1smd




msg:4613795
 3:15 pm on Sep 30, 2013 (gmt 0)

Rules with [R=301,L] flag should include protocol and hostname in the rule target.
Change this in every rule that redirects.

Patterns like
^investors/index\.php$
are better off expressed as
^investors/(index\.php)?$
so that both URLs redirect.

Change all
Redirect 301 ... ...
rules to instead use
RewriteRule ... ... [R=301,L]
syntax.

Change rule target from
http://www.example.com?
to
http://www.example.com/?
as the trailing slash is important.

Change RegEx pattern from
!^www\.example\.com [NC]
to
!^(www\.example\.com)?$
so that it redirects ALL hostname requests that are not "exactly" www.example.com

Change
^/assets/pdf/(.*)$
to
^assets/pdf/(.*)
as the leading slash is a typo.

lucy24




msg:4613807
 4:19 pm on Sep 30, 2013 (gmt 0)

Patterns like
^investors/index\.php$
are better off expressed as
^investors/(index\.php)?$
so that both URLs redirect.

If you want to cover all possible type-ins,
^investors(/(index\.php)?)?$

If the physical directory still existed, the directory-slash redirect would kick in automatically. So it's only fair to code it explicitly when redirecting everyone else.

Force10x




msg:4613874
 12:48 am on Oct 1, 2013 (gmt 0)

Damn! So disappointed.
I thought that was "THE" code with no errors and would get a thumbs up from all you guys.

Thanks for correcting the errors and providing reasons as to why they are incorrect.

I am a bit confused now.

Patterns like
^investors/index\.php$
are better off expressed as
^investors/(index\.php)?$
so that both URLs redirect.


In the above code, won't www.example.com/investors redirect to the same page as www.example.com/investors/index.php?page=16

The current CMS has different content for each of the following urls
www.example.com/investor
www.example.com/investor/index.php?page=11
www.example.com/investor/index.php?page=12
and so on.

hence why I want to treat it as a unique url and redirect to the new equivalent page.

I am using RewriteRule ^investors/(.*)$ to redirect anything under investors (other than the queries in RewriteCond)
investors/mymoney.php
investors/index.php
and investors/ will all direct to /aboutus/companyprofile which is the new page


Change rule target from
http://www.example.com?
to
http://www.example.com/?
as the trailing slash is important.


Isn't trailing slash for directories and folders only? these are not actual directories. The CMS displays pages without file extensions

lucy24




msg:4613890
 5:12 am on Oct 1, 2013 (gmt 0)

Oh, forgot we're in a CMS. If /investor/ (or is it /investors/ ?) isn't a real, physical folder then neither the final slash nor the /index.php makes a difference. Redirect only the URL that was formerly used.

directories and folders

directory = folder. Same word in different languages.

But now wait a minute.
RewriteRule ^investors/(.*)$ /aboutus/companyprofile? [R=301,L]
If the part in parentheses can be empty (length 0) and you're not reusing it in the target, what's it even there for? All you need is
^investors/
with no closing anchor.

Force10x




msg:4613891
 5:58 am on Oct 1, 2013 (gmt 0)

It is "investors". Aplogies, my bad.

my reason for using (.*)$ was to redirect anything after investors to the target folder.
e.g
investors/mymoney.php
investors/index.php

my understanding is that a "*" used within a "( )" is used to group text for use with the quantifier in this case "*"

perhaps ^investors/ with no closing anchors means
everything after investors/
e.g. investors/mymoney.php
investors/index.php

I'm sorry.
the more Im trying to understand the more confused I am getting and eating up all you lovely people's time

lucy24




msg:4613897
 7:45 am on Oct 1, 2013 (gmt 0)

.*
= "zero or more characters"
= "there may or may not be stuff here"

(blahblah)
= capture whatever is inside the parentheses so that it can be reused later

^investors/.*$
=
^investors/
The first form means "there might be more stuff between the part I've spelled out and the end of the test string".
The second form means "it doesn't matter what comes after the part I've spelled out".

See how they're identical? The .* element is irrelevant unless you need to capture it for later reuse.

If you don't plan to reuse it, you don't need to capture it.
If it doesn't have to exist at all, you don't need to test for it.


perhaps ^investors/ with no closing anchors means
everything after investors/
e.g. investors/mymoney.php
investors/index.php

Oh, you know what? You may be confusing mod_rewrite syntax with mod_alias (Redirect by that name). In mod_rewrite, nothing is reused unless it's explicitly captured and then named in the target. (Same pattern as RewriteMatch.)

Redirect 301 ^investors/ http://www.example.com/litigants/

= "take anything that comes after /investors/ in the request, and instead attach it to /litigants/"

RewriteRule ^investors/ http://www.example.com/litigants/ [R=301,L]
= "take all requests for anything in /investors/ and redirect them to the front page of /litigants/".

If you want to replicate the mod_alias (Redirect 301) behavior, you have to say
RewriteRule ^investors/(.*) http://www.example.com/litigants/$1 [R=301,L]
g1smd




msg:4613922
 8:55 am on Oct 1, 2013 (gmt 0)

This suggestion appears to have caused some confusion:

"Patterns like
^investors/index\.php$
are better off expressed as
^investors/(index\.php)?$
so that both URLs redirect to the same place."

Remember that your original rule using that pattern also has this test:
RewriteCond %{QUERY_STRING} (^|&)page=22(&|$)

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.

With your new rules, the first of those requests now redirects to
example.com/aboutus/companyprofile/press
while the other one redirects to
example.com/aboutus/companyprofile
as that request matches a different later rule.

I would have assumed that the "page=22" part drove the decision as to the target, so the "index.php" part can be optional.

This suggestion does NOT make the slash optional, and therefore has NO effect on requests for
example.com/investors
Force10x




msg:4614137
 1:24 am on Oct 2, 2013 (gmt 0)

After my last attempt, i'm not so confident.
Here is my updated code


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]



@lucy24
Thank you for explaining that so well.
That mod_alias makes so much sense now

@g1smd
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.


You are 100% right.

However, example.com/investors/index.php?page=22 is different from example.com/investors/index.php

Hence why I have these two sets of code.

#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]
This 38 message thread spans 2 pages: 38 ( [1] 2 > >
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved