How to redirect a non-existing directory to a sub-domain - apache

During the last 2 hours I'm trying to achieve the following with no success.
I have a domain (lets call it www.test.com) which is assigned to a specific folder in my host, for example : public_html/test.
Now, what I'm trying to do is, I want to redirect a specific url (www.test.com/move) to a subdomain that exists and is assigned to another folder inside the public_html.
I want this to happen only for the specific directory (move) which does not exist inside the test folder.
I guesss this can be done through .htaccesss but I fail miserably every time.
Any ideas on what I miss?

This is really simple if you only want to do that specific URL.
RewriteEngine On
RewriteRule ^move$ http://subdomain.test.com [R=301,L]

Related

How to get last part of URL to process in parent directory without creating a new child directory

I have a url similar to:
https://example.com/event/FI42382
I have created a folder named event from which I want to use PHP to process the FI42382 part.
However, the last part is treated as its own directory. What do I need to do so that it is not a directory and instead I can manipulate the last path as a variable in event/index.php?
Sorry if I have worded the title poorly. I wasn't sure how to explain this.
You need to pass value which you want to access through a query string to your index.php etc. In your .htaccess file try with following Rules once. Also make sure place your .htaccess file in root(same level along with your event folder is present, NOT inside event folder please). Later in your php code you could get/extract the var value which is passed to it.
Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule %{QUERY_STRING} ^$
RewriteRule ^event/(.*)/?$ event/index.php?var=$1 [NC,L]

How to do a basic, total, overall redirect with htaccess

For some time I used a free account to host my online forum. Recently I bought a domain name, and now it contains a full copy of all the php and mysql data in the forum, so now there are two copies of the forum in different locations. The last step I need to accomplish is to erase all the data in the old location, and replace it with a short htaccess file that will make a global redirect. What would the contents of this htaccess file look like ? I don't know enough Apache to be sure.
I found many related topics to this one here on MSE and elsewhere, but none that could match my needs exactly . Most are about redirections to just a subfolder inside a single server.
Note : the whole point of this question is that I wish the users of the forum to use the same URL as before, I wish to avoid to have to tell everyone that the forum's URL has changed. Nonprofessional users dislike changes
If mod_alias is active:
Redirect 301 / http://your-new-site.com
otherwise, if mod_rewrite is active:
RewriteEngine On
RewriteRule ^ http://your-new-site.com%{REQUEST_URI} [R=301,L]

.htaccess redirect match to subfolder

I have the present structure now:
www.site.com/reportddmmyyyy
ex:
www.site.com/report01012015
www.site.com/report05012015
and I would like to move all the reports directory into a main directory: reports
www.site.com/reports/reportddmmyyyy
ex:
www.site.com/reports/report01012015
www.site.com/reports/report05012015
Many users have the old format in their bookmarks, so I need htaccess to detect that someone tried to access www.site.com/reportddmmyyyy
and show the content of reports/reportddmmyyyy without changing the browser URL.
Is it possible? I have been Googling for a long time but maybe I am not searching correctly. Could someone please point me in the right way?
RewriteEngine On
RewriteRule ^report([^/]+)/?$ /reports/report$1 [NC,L]
This rule will rewrite
/report01011990
to
/reports/report01011990
without changing the url in your browser.

Using .htaccess to make subdirectory act like subdomain

It's a little difficult for me to ask the question correctly in title, but mainly here's what I'm trying to figure out.
If I use .htaccess on my website and say I'm trying to create a specific path "redirect" so that anything inside that path uses it's non-redirected path for it's relative path. Sorry for the structure of that sentence.
So for example...
I have my website as-
http://www.example.com/
I want to keep things organized so I create a sub-folder/subdirectory to keep all these folders inside of.
http://www.example.com/projects/
So the folder projects will be the place holder for all future projects and I want to create a folder inside projects for each project, so that I can define a URL for each one like such...
http://www.example.com/SuperFish/
http://www.example.com/AquaFear/
Now the folder for SuperFish and AquaFear would be under http://www.example.com/projects/ but also in their own folder say...
http://www.example.com/projects/01/
http://www.example.com/projects/02/
Now it'd be fine and dandy to keep the links like such, but for memory purposes and to share with other people the links to those projects, I'd like to just create a nice simpler URL with a custom "name". like http://www.example.com/SuperFish/ instead of http://www.example.com/projects/01/.
Now I was able to do this partially with my .htaccess file in the root folder with this code...
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^SuperFish/?$ projects/01/ [NC,L]
RewriteRule ^AquaFear/?$ projects/02/ [NC,L]
The issue with this though is that now I can't use relative paths with my SuperFish or AquaFear made up URL links. Anything such as .css, .js, .etc... Isn't within scope because it's trying to look for those files through the made up URL rather than the real physical one.
So the question is, how would I make it so that I can use my made up URL and also have the webpage load things to the real physical path or somehow fix the relative paths by doing this within the .htaccess file?
The reason I titled this the way it is, is due to subdomains being able to find their files with relative paths even though they're a subdirectory just the same.
Using final $ blocks files inside this two folders from being redirect correctly. You could tried instead :
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^SuperFish/?(.*)$ projects/01/$1 [NC,L]
RewriteRule ^AquaFear/?(.*)$ projects/02/$1 [NC,L]

Add on domain mod rewrite to create pretty url

I have a main website www.site.co.uk and one of my add on domains is addon.co.uk. Site has an htaccess as does addon. The folder of which from the root would be www.site.co.uk/addon.co.uk/.htaccess ..I think!
Anyway currently I can do redirects within addon htaccess file fine, but its a database driven site and im trying to create pretty urls for it, so:
http://www.addon.co.uk/addonsites/some.php?id=page
would become:
http://www.addon.co.uk/id/page/
The mod I have in the addon htaccess file is the following:
RewriteEngine On
RewriteRule ^id/([^/]*)/$ /addonsites/some.php?id=$1 [L]
But this has no effect.
Well, the mod_rewrite module will perform translations on requests to the server, so when anyone requests the resource located at http://www.addon.co.uk/id/page/ the server will know that http://www.addon.co.uk/addonsites/some.php?id=page is the place to go.
However, mod_rewrite does in no way modify your existing links. I.e., you should rewrite the HTML (or scripts generating the HTML) to match the "new" way of linking. E.g., if you have ... somewhere on your site, you must make sure it is changed to ....
tl;dr
mod_rewrite handles incoming requests; it does not modify your output (HTML).