0

I would like to ask you a question. Is it possible to redirect the old URL to a new url (old sub-page to new sub-page) (301 redirect) in Apache through etc/apache/sites-available/...conf file?

I found this code. I am not sure if it works. The problem is that it's not a redirection of sub-pages.

<VirtualHost *:80>
ServerName www.domain1.com
Redirect 301 /oldlocation http://www.domain2.com/newlocation
</VirtualHost>

I am not very good at this so any advice is greatly appreciated.

2
  • I've done the research for your offtopic question here's a tutorial and shortly said yes it is possible
    – djdomi
    Oct 14 at 7:34
  • NEVER EVER CONFIGURE A 301 REDIRECT until you've got the desired configuration working with a 302.
    – symcbean
    Oct 15 at 0:16

1 Answer 1

0

Apache conf files have their own syntax. In my experience, it takes some exposure and experimentation before one starts to understand them. Your example uses the Redirect directive, which appears to be implemented as part of mod_alias. Your apache server may or may not have mod_alias enabled. To see what apache modules are enabled, see this thread.

The Redirect directive doesn't look very flexible. The docs say:

The Redirect directive maps an old URL into a new one by asking the client to refetch the resource at the new location.

The old URL-path is a case-sensitive (%-decoded) path beginning with a slash. A relative path is not allowed.

The new URL may be either an absolute URL beginning with a scheme and hostname, or a URL-path beginning with a slash. In this latter case the scheme and hostname of the current server will be added.

Then any request beginning with URL-path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-path will be appended to the target URL.

You might consider checking out mod_rewrite which is more advanced & flexible. It implements pattern matching behaviors which will probably give you more powerful ways to send an old url to new one. Your post appears to redirect not just to a new domain but also changes 'oldlocation' to 'newlocation'. You may need to implement some kind of elaborate RewriteMap thing, depending on how you have changed your urls.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .