0

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!

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

1 Comment

I apologize for the late reply, but I wanted to make sure I wasn't making any other mistakes before responding. This change seems to make no difference. Using this file causes an internal server error regardless of what comes after the directory. Is there something in the default configuration that needs to be changed? Is there a simpler solution? I basically just want to add ?email= to whatever the URL says and then stop redirecting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.