I am trying to do an SEO-friendly URL in the CloudWays server but it’s not working. Also, When I try it in the localhost or Cpanel it works fine.
Thanks!
This is my .htaccess file code:-
Options +MultiViews
RewriteEngine On
# Set the default handler
DirectoryIndex index.php index.html index.htm
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php/$1 [L]
RewriteRule ^validate/([a-zA-Z0-9-/]+)$ search.php?phoneNumber=$1
RewriteRule ^validate/([a-zA-Z-0-9-]+)/ search.php?phoneNumber=$1
This is the main link:-
https://example.com/search.php?phoneNumber=16503858068
And I want it like this:-
https://example.com/validate/16503858068
2
Answers
Look at
RewriteRule (.*) /index.php/$1 [L]
.The
L
option means the parser stops at this redirect rule if it matches.Since
(.*)
will match everything the rule is applied and the following rules will not be applied ever.To fix this you can prepend your own rules to this rule, but make sure to use the
L
flag as well else the(.*)
rule will overwrite it again.That’s also answered here:
multiple rewriterules
Your rules are in the wrong order. The last two rules (which can be combined into one) are never processed because a URL of the form
/validate/16503858068
is routed to/index.php
by the preceding rule.Try it like this instead:
Note the
L
flag on the first rule.Also, you should probably disable MultiViews. For some reason you were explicitly enabling this?