logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: point to another page
Author
Danll



Joined: 02 Aug 2013
Posts: 49
Location: USA, Houston

PostPosted: Mon 20 Jan '14 1:49    Post subject: point to another page Reply with quote

OK, I want people who are going to name1.htm on my website to go to name2.htm instead. When people ask to go to name1, how do I automatically lead them to name2?

I *thought* it was an easy

Redirect name1.htm name2.htm in my .htaccess file.

But that doesn't work. The site refuses to load if I do that. Maybe because name1 no longer exists? So, aside from just copying the contents of name2 into the file name1, how do I do it??
Back to top
Anaksunaman



Joined: 19 Dec 2013
Posts: 54

PostPosted: Mon 20 Jan '14 10:40    Post subject: Post subject: point to another page Reply with quote

You didn't specify details, but if these are old pages here's a few things to try:

In case you need more specificity (required by some hosts, such as GoDaddy):
Code:
Redirect /foldername/name1.htm http://example.com/name2.htm

Permanent redirects are 301:
Code:
Redirect permanent /name1.htm http://example.com/name2.htm

Code:
Redirect 301 /name1.htm http://example.com/name2.htm

Using RedirectMatch with RegEx to make sure that ONLY this page is redirected:
Code:
RedirectMatch 301 ^/name1\.htm$ /name2.htm

With a full domain to avoid issues with URL variables:
Code:
RedirectMatch 301 ^/name1\.htm$ http://example.com/name2.htm

Using mod_rewrite as opposed to mod_alias, again as a permanent redirect:
Code:
RewriteEngine On
RewriteRule ^name1.htm http://www.example.com/name2.htm [R=301,L]

Note that you should pick one or the other. Technically, mixing mod_alias and mod_rewrite in the same .htaccess file can potentially cause screwy behavior.

You may also want to verify your .htaccess files are working in the first place.
Back to top
Danll



Joined: 02 Aug 2013
Posts: 49
Location: USA, Houston

PostPosted: Tue 21 Jan '14 0:16    Post subject: Reply with quote

Thank you. What worked was

Code:
Redirect permanent name1.htm http://example.com/name2.htm


(or without the permanent/301)

This is with Apache 1.3.33 BTW.

I'm not sure I understand why one needs a different command to make sure that only that page is redirected. Why would any other page get redirected if I didn't use RedirectMatch?
Back to top
Anaksunaman



Joined: 19 Dec 2013
Posts: 54

PostPosted: Tue 21 Jan '14 9:37    Post subject: point to another page Reply with quote

Ok maybe I phrased that badly. Laughing

You are absolutely right -- Redirect should not cause issues. You shouldn't get errant redirection unless you are (mis?)using RedirectMatch. The example assumes that RedirectMatch was substituted for Redirect but kept the same format as your original post example. Smile

You seem to understand the uses of Redirect vs. RedirectMatch, but for anyone else reading this post, here is a bit of a breakdown on RedirectMatch:

Per the Apache docs on RedirectMatch:
Code:
This directive is equivalent to Redirect, but makes use of standard regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename. For example, to redirect all GIF files to like-named JPEG files on another server, one might use:

    RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg

So essentially, there is the potential for similarly named pages/paths to cause unintended consequences when redirecting using RedirectMatch.

To clarify, when using RedirectMatch, /name1.htm essential means "any path that contains" but technically does not mean "any URL path that is exactly". This is a specific case in regular expression matching and only really applies to RedirectMatch, as (as mentioned above) the directive is built specifically for use with regular expressions. For this "cure", the assumed (bad) URL would be something like:

Code:
RedirectMatch 301 /name1.htm /name2.htm

So that:

Code:
/name1.htm
/url1/name1.htm
/example/name1.htm

would all be redirected, not just /name.htm. Dependent on circumstances, using RedirectMatch (as opposed to Redirect) to facilitate the ability to use regular expressions is desirable and the example format in the previous post helps avoid unintended pitfalls when RegEx matching.

Oh, and BTW, I should just note for the sake of good web practices, if the page no longer exists, using the 301 or permanent versions is the "best" way to do things. Wink
Back to top
Danll



Joined: 02 Aug 2013
Posts: 49
Location: USA, Houston

PostPosted: Tue 21 Jan '14 16:50    Post subject: Reply with quote

OK, that helps a lot. I guess you'd use RedirectMatch if you had a file living in several different places, and that file, in all of those places, was to be superseded by another one. So instead of Redirect-ing every single one of those files in their different locations, you just do it in bulk. That's handy to know about.
Back to top


Reply to topic   Topic: point to another page View previous topic :: View next topic
Post new topic   Forum Index -> Apache