Htaccess - rewriting subfolder names as GET parameters - .htaccess

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]

Related

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]

htaccess redirect all liks but specific ones

how can I do this in htaccess
I have
/main_dir/([a-z-]+)/dir1 - this should remain as it is
/main_dir/([a-z-]+)/dir2 - this should remain as it is
/main_dir/([a-z-]+)/dir2/UQ13A -this should remain as it is
but
/main_dir/([a-z-]+)/UQ13A -should take me to /main_dir/$1/dir2/UQ13A
UQ13A - can be any string containing [a-zA-Z0-9-]
I am not so familiar with negative lookahead, lookbehind
for now I have something like
/main_dir/([a-z-]+)/(?!(dir1|dir2)) /main_dir/$1/dir2/$2
which is not working
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
RewriteRule ^main_dir/([a-z-]+)/(?!(?:dir1|dir2)/)(.+)$ /main_dir/$1/dir2/$2 [L,NC]

htaccess redirect homepage to subdirectory keep url the same

I am trying to figure out how to get my .htaccess to redirect just the homepage URL to a sub directory (domain.com > domain.com/sub/sub ), but I still want the URL to display as domain.com.
I looked around for the past hour and have tried a number of suggestions that I found but nothing worked out.
Any Ideas?
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 ^$ /sub/sub [L]

htaccess url issue

I am trying to redirect all pages(domain.com/xxx-xxx-xxx) to new urls domain.com/np/xxx-xxx-xxx and i have tried following rule...
RedirectMatch 301 ^/([^\-]+)-([^/]+)-([^/]+) /np/$1-$2-$3/
It works but it is appending too many /np in url, check following for example
I have tried accessing http://www.domain.com/web-design-services and it becomes http://www.domain.com/np/np/np/np/np/np/np/np/np/np/np/np/np/np/np/np/np/np/np/‌​np/web-design-services can you please explain why is this happening?
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 ^([^-]+-[^-]+-[^-]+)/?$ np/$1 [L,R]

Remove folder with 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]

Resources