Redirect every incoming request to specific path preserving file and query?

0

Issue

As I’m not strong with apache could someone point me in right direction with this?

I currently have urls like this
www.domain.com/public/my_file.php?query=thing&another=thing

What I’m looking to do is to rewrite my code so i it don’t use /public/ part anymore, but after that i still need to support all crawlers and old urls people are linking to.

So how would i do 301 redirect preserving everything that comes after public/ part?

(Example) Need to redirect something like this
www.domain.com/public/my_file.php?query=thing&another=thing
into this
www.domain.com/my_file.php?query=thing&another=thing
with 301 redirect.

Thnaks.

Solution

Redirect 301 /public/my_file.php /my_file.php

The query string gets passed along by default.


EDIT:

To redirect everything in the public folder, use this:

RedirectMatch 301 /public/(.*) /$1

Answered By – Jon Lin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More