htacess folder redirecting and keeping file

I have this in my htacess file
i am trying to change it so anything from the subfolder state should redirect to my main site index page.

RewriteRule ^state\/$ "http\:\/\/www\.site\.org\/" [R=301,L]

but instead let's say I have the www.site.org/state/ohio.html, it redirects to www.site.org/ohio.html
what needs to be adjusted?
rivkamakAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Franck HorlavilleTechnical DirectorCommented:
Hi, try using RedirectMatch instead as such:

RedirectMatch 301 ^/state/$ http://www.site.org/

Open in new window



Source: https://perishablepress.com/redirect-subdirectory-to-root-via-htaccess/

Franck
0
rivkamakAuthor Commented:
nothing happens when i use redirectmatch.
0
Franck HorlavilleTechnical DirectorCommented:
Is mod_alias enabled ? Here is its documentation, with all the possible redirects it allows
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

hieloCommented:
If all you want to do is redirect:
"www.site.org/state" OR  "www.site.org/state/"
to www.site.org, then try:

RedirectMatch 301 ^/?state/?$ http://www.site.org/

Open in new window


If you also want to redirect  www.site.org/state/ohio.html  to www.site.org/ohio.html, then try:

RedirectMatch 301 ^/?state/(.+)$ http://www.site.org/$1
RedirectMatch 301 ^/?state/?$ http://www.site.org/

Open in new window

0
rivkamakAuthor Commented:
sorry for not being clear.
I want to redirect  www.site.org/state/ohio.html  to www.site.org/
I need any subpages of the folder state, to just redirect to the main site index page.
i can't get that to work.
0
hieloCommented:
try:
RedirectMatch 301 ^/?state/(.+)$ http://www.site.org/

Open in new window

0
rivkamakAuthor Commented:
Nope. it's not working, the ohio.html is staying at the end after the redirect.
0
hieloCommented:
Redirect and RedirectMatch are mod_alias directives.
http://httpd.apache.org/docs/2.2/mod/mod_alias.html#RedirectMatch

However, AFAIK, mod_rewrite rules take precedence.  Try converting the mod_alias rule to the equivalent mod_rewrite rule (given below).  

>> the ohio.html is staying at the end after the redirect.
I suspect you have some other mod_rewrite rule that is conflicting with the mod_alias rule suggested earlier.  Try the code below.

# .htaccess begins here
RewriteEngine On
RewriteBase /

RewriteRule ^/?state/(.+)$ http://www.site.org/ [R=301,L]

# other rules follow ...

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.