Reputation: 1
I'm trying to make my URLs look "nicer". Instead of x.com/reset-password/[email protected], I want it to be x.com/reset-password/[email protected]
Using mod_rewrite, I've gotten it to work for every relevant string except those with periods (.). When I allow dots in the RewriteRule statement, an internal server error occurs. I think it's because even when the L flag is applied, it must redirect one final time to the new destination and therefore going into an infinite loop since my regex is too lenient.
I'm trying to use a RewriteCond to stop any URIs with an equals sign from redirecting, thus solving the infinite loop problem, but it's not applying correctly. I'm asking for one of two solutions, I guess: either a way to include periods in the original regex or a way to stop URIs with = from being evaluated
The original regex:
RewriteRule ^([^.]+)$ ?email=$1 [L]
The modified one:
RewriteCond %{REQUEST_URI} ^[^=]+$
RewriteRule ^(.+)$ ?email=$1 [L]
I know there are a lot of regex/htaccess tutorials online (I've spent the last several hours reading them...), but I can't seem to figure it out. Any help is appreciated!
Upvotes: 0
Views: 182
Reputation: 141907
You should be using the QUERY_STRING
instead of the REQUEST_URI
since the =
is in the QUERY_STRING
:
RewriteCond %{QUERY_STRING} ^[^=]+$
RewriteRule ^(.+)$ ?email=$1 [L]
Upvotes: 1