views:

60

answers:

3

Hello,

I'm trying to forward example.com/signup and example.com/signup/ (with trailing slash) to example.com/signup.php

I wrote following to .htaccess and it works for example.com/signup/ but doesn't work without trailing slash... How can I solve the problem?

RewriteEngine On
RewriteRule ^question/(.*)-(.*) /question.php?qid=$1
RewriteRule ^signup/ /signup.php
+3  A: 

Make the slash optional with the ? quantifier:

RewriteRule ^signup/?$ /signup.php

But I recommend you to just use one notation and redirect the other one.

Gumbo
+4  A: 
RewriteEngine On
RewriteRule ^signup/?$ /signup.php

The question mark makes the slash optional, and the dollar sign means end-of-line, so nothing can follow. You can remove the $ if you like.

You could also allow arbitrary query strings at the end of the URL with something like:

RewriteRule ^signup/?(\?.*)?$ /signup.php$1

That would allow you to pass any query parameters on to your PHP script. For example the URL http://www.example.com/signup?destination=/front-page would be redirected to http://www.example.com/signup.php?destination=/front-page.

John Kugelman
thank you very much John! :)
she hates me
+1  A: 

Put a question mark after the slash

RewriteRule ^signup/? /signup.php

? = optional single character in regex matches

Devin Ceartas