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
-
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.
-
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 tohttp://www.example.com/signup.php?destination=/front-page
.she hates me : thank you very much John! :) -
Put a question mark after the slash
RewriteRule ^signup/? /signup.php
? = optional single character in regex matches
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.