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
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
.
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.
Put a question mark after the slash
RewriteRule ^signup/? /signup.php
? = optional single character in regex matches
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.