balanv
balanv

Reputation: 10888

.htaccess issue with redirecting folder

I have a folder named /test in my application.

Right now i am trying to write an .htaccess file that would show all requests to /test* as /test.

For example:

www.example.com/test/ is the actual directory with index.php file in it.

All the requests like the following should go to the same /test directory

www.example.com/test-hello/
www.example.com/test-world/
www.example.com/test-htacess/
www.example.com/test123/

Basically any requests to /test* should go to /test.

This is what I've tried so far:

RewriteRule ^/test* /test

Upvotes: 1

Views: 84

Answers (3)

user319198
user319198

Reputation:

You need to use RewriteCond to first match "test in url"

Try below:

RewriteCond %{THE_REQUEST} ^GET\ /test/
RewriteRule ^test/(.*) /test/$1 [L,R=301]

Upvotes: 2

Niels
Niels

Reputation: 49919

You currently are not putting the -hello, -world etc behind your folder. What is hello? Is that the file? Or the param?

The second part of the rewriteRule should be a file. Something like

RewriteRule ^/test(.*)$ /test/$1.php

Above function will have:

/testABC to /test/ABC.php

But I don't understand what you want to accomplish?

Upvotes: 1

rekire
rekire

Reputation: 47945

Your regular expression is wrong. You mean ^/test.*$. Your rule would match to /testtttt.

The asterisk means that the char in front of it can be zero or more times included. The dot is a special char which means here could be anything. the .* matches every string including an empty string. See also Wikipedia.

Upvotes: 2

Related Questions