124697
124697

Reputation: 21893

How can i redirect all subfolders to a single root folder

I am trying to redirect all calls to mysite.com/api/foo/bar/json?param1=1... to mysite.com/api

I've tried

RewriteEngine On
RewriteRule "^api/?(.*)" "/api" [R=302]

But it doesn't work because it redirects in a loop

Upvotes: 1

Views: 86

Answers (2)

Amit Verma
Amit Verma

Reputation: 41219

You need to exclude the destination path you are redirecting to

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/api/?$
RewriteRule ^api/?(.*) /api [R=302]

Upvotes: 1

claudios
claudios

Reputation: 6656

First check file permission maybe you don't have to made edit on the .htaccess file. Then insert this line of code.

RewriteEngine on

RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

Upvotes: 0

Related Questions