Having trouble with Apache Redirect 301 from domain to sub

Hello. This has been driving me crazy all weekend.

I am using Apache2 and am trying to get a 301 Redirect of eight specific links to its new site. The new site is on its own server. The current url is, e.g., http://www.example.com/products/type/great-product, where the redirect target is sub.example.com/product/type/great-product

What do I need to do to successfully get these redirects to work? I don't want to use the htaccess file unless necessary, I hear it is better to do this in a separate vhost???

Thanks!

Here is a sample of the redirects I created:

Redirect 301 /products/type http://sub.example.com/products/
Redirect 301 /products/type/widgetsandaddons/2/ http://sub.example.com/products/2
Redirect 301 /products/type/widgetsandaddons/3/ http://sub.example.com/products/3
Redirect 301 /products/type/widgetsandaddons/4/ http://sub.example.com/products/4

5 Replies

Is modalias loaded? You can check with apachectl -M (or apache2ctl -M on some distros). If there isn't a line saying "aliasmodule" then you'll need to enable it.

Hi, thanks for getting back to me! Yes, alias_module is loaded…

In your example, http://www.example.com/products/type/great-product would redirect to http://sub.example.com/products//great-product . First, you should leave the trailing slashes off all the URLs and URL-paths. Second, make sure the destination pages live at the URLs you're redirecting to. Third, check the Apache logs to see what's happening? The docs may help; I don't think I have much else to offer at this point…

Have you reloaded the Apache config as well?

If you put the new configuration in a .htaccess file, no reload is necessary, but if you put these directly in a vhost config file, you need to reload the config with /etc/init.d/apache2 reload.

I'd use this in the VirtualHost config:

ProxyPass /products/type http://sub.example.com/products/

ProxyPassReverse /products/type http://sub.example.com/products/

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct