Cannot 301.htaccess redirect in XAMPP - apache

A simple working 301 .htaccess redirect on my live server looks like this:
Options +FollowSymLinks
RewriteEngine on
redirect 301 /test.php /index.php
But I can't make it work my XAMPP installation.
I have enabled mod_rewrite.so in the http.conf file and I can't see why it does not redirect. Have restarted apache but no luck.

Just to let you know that Apache's redirect directive is from mod_alias module not from more_rewrite module. Check docs here: https://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect
If you want to handle it via mod_rewrite it then use it like this:
RewriteEngine on
RewriteRule ^test\.php$ /index.php [L,NC,R=301]
ALternatively enable mod_alias module to make redirect work.

Got it working by creating a local domain Using Apache Virtual Hosts. Once the local domain is setup, the redirect code works as it does on the live server:
redirect 301 /test.php /test2.php.php

Related

how to configure Apache to redirect test.com to test.com/admin

How do I configure Apache to redirect test.com to test.com/admin ?
I would prefer to use mod_rewrite but it is not required. All the posts I see on Apache redirection seems to focus on redirecting all uri's to a single uri.
With mod_rewrite, you can just do RewriteRule ^$ admin. That will redirect / to /admin.

How to redirect to subdomain but then allow normal use of site

So I have my site, www.domain.com.
For a week or so I want to direct all traffic going direct to the site to subdomain.domain.com, a little promo page about an upcoming feature. I want visitors to then be able to continue to the site as normal though after they've read it, so a continue to www.domain.com/index.php link.
How can I do that with in the htaccess file? Everything I've tried so far messes up when clicking the continue link.
Thanks
with .htaccess you could use a 302 temporary redirect, but it would be for a whole sub folder as far as I know.
Another way would be to redirect with JS/server site language to the subdomain, create a cookie, then redirect back to www.domain.com/index.php .
the 302 redirect is explained here: How do I redirect my site using a .htaccess file?
You would need to have a .htaccess for the root folder point to your subdomain
Note that this is only possible if you enable mod_proxy in the Apache config of domain.com otherwise URL will change after redirect.
Enable mod_proxy, mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^index\.php$ http://subdomain.domain.com/ [L,NC,P]

htaccess redirect error in domain example.com:443

I've got a problem with a htaccess redirect.
What I like to do:
I want to redirect the link https://www.example.com/folder to https://www.example.com/folder/subfolder.
So normally I would use:
redirect /folder /folder/subfolder
But I've got the problem, that my browser is redirected to http://www.example.com:443/folder/subfolder. So no https but a nice :443 at the end. And the browser gives me an 404 error.
Does anybody has an idea how I can redirect the url correctly?
Thank you.
Try this instead:
redirect permanent /folder https://www.example.com/folder/subfolder
EDIT: If mod_alias isn't working for you you can try using mod_rewrite based rule like this:
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^folder/?$ https://www.example.com/folder/subfolder [L,R=301,NC]

redirect blog.mydomain.com

I currently have a wordpress blog located at blog.domain.com and my regular website at www.domain.com, both hosted on an apache server.
my website root has it's own .htacess file, and my blog root has an .htaccess file.
virtual hosts are setup within the httpd.conf file
everything works as it should, what I'm trying to figure out is how to set-up the following redirects.
main blog
blog.domain.com - Redirect to - www.domain.com/blog
all the blog articles
blog.domain.com/blog/article_name - redirect to - www.domain.com/blog/article_name
This needs to be seamless so we don't effect the permalinks already created within the blog
Does anyone have any ideas?
Using a Redirect rule in your .htaccess file on blog.domain.com:
Redirect 301 /blog http://www.domain.com/blog
Redirect 301 / http://www.domain.com/blog/
Seems like you have access to your apache's conf files.
I would suggest you to do this:
create separate Virtual host block to blog.domain.com.
<VirtualHost *:80>
ServerName blog.domain.com
#other settings
RewriteEngine on
RewriteRule ^(blog)(/.*)? http://www.domain.com/$1$2 [R=301,L]
RewriteRule ^(.*)$ http://www.domain.com/blog/$1 [R=301,L]
</VirtualHost>
Actually just the above will suffice.

Redirect subdomain to /folder

I want to redirect the sub-domain webmail to /roundcube for that domain. This have to work for all virtual hosts in apache.
Example:
webmail.example.com must point to [www.]example.com/roundcube
How is this possible? The server where it has to be done is configured with direct admin :S
mod_rewrite is your friend.
Try something like this in your Apache VirtualHost configuration:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^webmail\.[^.]+\.[^.]+$
RewriteRule ^webmail\.([^.]+)\.([^.]+)$ http://www.$1.$2/roundcube [R=permanent]
...and configure DNS to point webmail.example.com to the same server as www.example.com.