1

I have search and tried all possible solutions from Stackoverflow but nothing seems to work for my case.

I'm trying to rewrite this URL:
http://www.example.com/test/name.php?name=somename

to appear as
http://www.example.com/test/somename

This is what I have currently in my htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test/?$ /test/name.php/?name=$1 [NC,L,QSA]

Would appreciate if anyone can lend some help here as I have been stuck in this for more than a day. Thanks!

1
  • There's no regex placeholder after test/… Commented Aug 14, 2015 at 19:02

2 Answers 2

1
RewriteRule ^test/?$ /test/name.php/?name=$1 [NC,L,QSA]
                  ^---- "0 or 1 of the previous"

Because you've got ^$ anchors in there, you're basically saying

/test/
/test

Are the only two URIs which could match. you probably want

RewriteRule ^test/(.*)$ /test/name.php?name=$1

instead. "A url which starts with test/, and uses everything after test/ for the name parameter".

Sign up to request clarification or add additional context in comments.

Comments

0

Try to use RewriteBase!

RewriteEngine On
RewriteBase /test/

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . name.php?name=$1

Here "." is any request.

1 Comment

The OP is already using a root-relative substitution so RewriteBase is not actually required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.