Remove folder with HTACCESS - .htaccess

When users go to the following url:
http://mysite.com/folder/subfolder?a=blah&b=blah
I need to point them to content that is in the root folder while keeping the variables intact:
http://mysite.com/?a=blah&b=blah
Since http://mysite.com is a virtual host, this solution should also leave other base URLs alone.
I'd prefer not to do a full redirect because we use log tracking in our system and we need to have the headers return a 200 code for the logs (maybe this doesn't matter).
I know that this is a fairly straightforward question for someone who really understands .htaccess redirects. Thanks in advance!

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 /
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^folder/subfolder/?$ / [L,NC]

Related

htacces rewrite single file

I want to rewrite a specific file on my website to another one by using htaccess:
# General
RewriteEngine On
RewriteBase /
Options All -Indexes
Options +FollowSymLinks
# Rewrite file
RewriteRule ^/file.html$ /dir/file.html [L]
This is the .htaccess code i'm using based on snippets i found on the internet.
Somehow this is not working, the server is returning a 404-Not-found error.
I can't see any difference with example's that are said to work, like in
Rewriting path for a specific file using htaccess
Edit:
If I place file.html in the root-folder, I can view it. So the rewrite definitely is not happening.
RewriteRule does not receive leading slash. Write so:
RewriteRule ^file.html$ /dir/file.html [L]

How to rewrite the base URL?

I need to make a rewrite rule that if anyone writes website url (the main one),
www.domain.com
it will show
www.domain.com/1
But if someone looks for anything else, for example:
www.domain.com/2
it will show the requested url,
www.domain.com/2
I need only to rewrite the base root /.
Thank you for your help,
Adam :)
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 ^/?$ /1 [L]

Is this .htaccess rewrite even possible?

My co-worker is proposing a .htaccess rewrite rule to implement on our system. I'm not even sure if it's possible, and I want someone more educated than me on the subject to verify.
Here's the URL currently:
http://cms.phasesolutions.ca/themes/Default/page.php?slug=home
Here's how he wants it to show up:
http://cms.phasesolutions.ca/pages/home/
Is that possible? (where the variable for "?slug=", and the "Default" folder, are subject to change, depending which theme they're accessing and what slug they're specifying)
Let me know,
thanks
Posting a solution in case you need starting point.
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
# handles /Default/home/ to /themes/Default/page.php?slug=home
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$2.php -f
RewriteRule ^([^/]+)/([^/]+)/?$ /themes/$1/$2.php?slug=home [L,QSA]

Htaccess - rewriting subfolder names as GET parameters

Can somebody please tell me the exact code to convert #1 to #2? I'm new to .htaccess and I am having trouble with this.
http://www.domain.com/folder/subfolder1/subfolder2/subfolder3/
http://www.domain.com/folder.php?param1=subfolder1&param2=subfolder2&param3=subfolder3
I want the URL in the address bar to keep being #1 so that is what the user sees. Meanwhile, the server treats the URL as page #2 so I can use GET variables in my code.
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)/(subfolder1)/subfolder2/subfolder3/?$ /$1.php?param1=$2&param2=$3&param3=$4 [L,QSA,NC]

htaccess rewrite rule similar to WordPress

Ok I have a script in the folder 'intake'. The index.php file auto creates a list of urls. Those urls are in the format:
/intake/4/Westrop
I have an .htaccess file in the intake folder. I want it to redirect the url to a FILE.
The above example would then become /intake/redirect.php?id=4&name=Westrop
Here's what I have so far:
DirectoryIndex index.php
Options All -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/(.*)$ /intake/redirect.php?id=$1&name=$2 [L]
</IfModule>
But for some reason if I type /intake or /intake/index.php I get a 404 error. According to firebug its trying to take "intake" and turn it into "intake.php"
Any ideas?
Place the following code in .htaccess file in website root folder:
RewriteEngine On
RewriteRule ^intake/(\d+)/([a-z0-9\-_]+)$ /intake/redirect.php?id=$1&name=$2 [NC,QSA,L]
P.S.
Do not use this sort of pattern -- ^(.*)/(.*)$ -- in your case for longer URLs it will work not as you would expect. It will match your URL .. but in a wrong way.
Start your .htaccess with this option:
Options +All -MultiViews -Indexes

Resources