htaccess redirect without directory - .htaccess

I want to make a redirect (using .htaccess) to an external site that host where my app can be downloaded so I can give users a url to server.com/install but when I add
Redirect 301 / http://google.com/ to my install directory it redirects to http://google.com/install which is not what I want.
How can I accomplish this with htaccess?

Redirect automatically appends anything from the original URL to the new URL.
Give this a try:
Options FollowSymLinks
RewriteEngine On
RewriteRule ^/ http://google.com [L,R=301]
One more attempt, I added the RewriteBase and wildcard to match all. But I think the problem was that there was no trailing / after google.com. Maybe someone else will answer if this doesn't work.
Options FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://google.com/ [L,R=301]

Related

Unable to get .htaccess RewriteRule to work

I've been pulling my hair out trying to get a URL rewrite rule to work using .htaccess. Mod_rewrite is enabled and I have managed to get a 301 redirect to work (from /beta to /Beta/) so I know the .htaccess is able to work.
Basically I'm trying to get /Beta/Page.php?id=page&tab=services&tabid=tab1 to become /page/services (and ideally leave out the tabid if it's not going to break the site removing it).
The code I'm working with currently is:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/Beta/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ /Beta/Page.php?id=$1&tab=$2&tabid=$3
redirect 301 /beta http://www.example.com/Beta/
Any help would be gratefully received.
Remove the leading slash:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(Beta)/[^.]+\.php\?id=([^&]+)&tab=([^\s&]*)&tabid=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3/%4? [R=302,L]
RewriteRule ^Beta/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ /Beta/Page.php?id=$1&tab=$2&tabid=$3 [L,QSA]
This will externally redirect:
/Beta/Page.php?id=page&tab=services&tabid=tab1
to
/Beta/page/services/tab1
and rewrite same URI internally.
Also .htaccess is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule URI pattern.

htaccess URL rewrite rule for everything under a folder

I have looked but can't find anything that works. I have an old site that we have updated. They had everything under a folder called site under the root. Now all the customers who have this bookmarked I would like to redirect them, regardless of what is after the folder site (subfolders, files), to the main page of the new site instead of page not found on our new WordPress install. Any help appreciated.
Old URL: http://www.oldsite.com/site/.... to new URL http://www.newsite.com
I have tried this to no avail
Rewrite Rule ^site/(.*)$ http://www.newsite.com
Thanks.
try:
RewriteEngine On
RewriteCond %{HTTP_HOST} oldsite.com$ [NC]
RewriteRule ^site/(.*)$ http://www.newsite.com/$1 [R=301,L]
This redirects something like http://www.oldsite.com/site/some-page.html to http://www.newsite.com/some-page.html (the matching bit of the URI after /site/ gets carried over in the 301 redirect), but if you want to redirect everything for /site/ to the index root of newsite, replace the target in the RewriteRule to http://www.newsite.com/ (remove the $1 bit).
EDIT:
I actually write it wrong above. It is actually the same domain name. The question should read old URL mysite.com/site.... everything under this folder to just redirect to mysite.com
Then what you want is:
RewriteEngine On
RewriteRule ^site/(.*)$ /$1 [R=301,L]
Or alternatively with mod_alias:
RedirectMatch 301 ^/site/(.*)$ /$1
Looks like all you need is this simple 1 liner rule:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^site/ / [R=301,L,NC]

Create a 301 redirect in .htaccess for folder to subdomain AND redirect www to non-www

I've searched everywhere and used some examples but they don't meet my specific needs, hence why I'm asking here if anyone can please help? I know the http:: below isn't correct, it's just because I can't post links here.
I'd like to redirect http:://www.mysite.co.uk/ to http:://mysite.co.uk/
whilst also being able to redirect
http:://www.mysite.co.uk/mysub/
and 2. http:://mysite.co.uk/mysub/
to 3. http:://mysub.mysite.co.uk/
All files in 1. and 2. should be redirected to their equivelant in 3.
For example: http:://www.mysite.co.uk/mysub/file.html AND http:://mysite.co.uk/mysub/file.html should both go to http:://mysub.mysite.co.uk/file.html
This is to affect the subdomain only, so that other folders and files in the site root aren't affected.
If anyone could help me understand and write the code for the 301 redirect in a .htaccess file I'd really really appreciate it! Thanks!
This is the code you'll need in your .htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
# To redirect http:://www.mysite.co.uk/ to http:://mysite.co.uk/
RewriteCond %{HTTP_HOST} ^www\.(mysite\.co\.uk)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# To redirect /mysub/foo to http://mysub.mysite.co.uk/foo
RewriteCond %{HTTP_HOST} ^(www\.)?(mysite\.co\.uk)$ [NC]
RewriteRule ^(mysub)/?(.*)$ http://$1.%2/$2 [R=301,L,NC]

htaccess non permanent redirect (301)

I'm trying to redirect every visitor that tries to enter my homepage (http://www.mysite.com/) to the Pub directory (http://www.mysite.com/Pub/)
I want the url field to show http://www.mysite.com and not http://www.mysite.com/Pub/
I've tried this, but for some reason it doesn't work:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule / /Pub/
Thanks,
The answer is here:
how to mask URL with htaccess?
long story short - it's impossible to show http://www.mysite.com and not http://www.mysite.com/Pub/.
Btw - you mean permanent redirect (301) or non permanent redirect (307)?
Have your rule in .htacess like this:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteRule ^/?$ /Pub/ [L]
It is important to not use R flag above so that its an internal redirect only without changing URL in the browser.

subdomain redirection using htaccess

I need to redirect the url http://testing.domain.com/ to http://testing.domain.com/admin/index.php
I think you are trying to secure your home page. Put this php code in your index.php.
header("Location: http://testing.domain.com/admin/index.php")
exit;
If you got everything in admin folder, then you can use this one
Options -Indexes
RewriteEngine on
RewriteCond $1 !^(admin)
RewriteRule ^(.*)$ admin/index.php [L]
Put the following into your .htaccess file
Redirect 301 http://testing.domain.com/ http://testing.domain.com/admin/index.php

Resources