But that redirects to
That is caused by the first (original) rule. Note that the earlier (erroneous) 301 will likely have been cached by the browser. Test with 302 (temporary) redirects to avoid potential caching issues.
Redirect directive is prefix-matching (whole path segments), and everything after the match is appended to the end of the target URL. So, the first directive redirects:
If the directives are ordered like this then they should "work" for the two example URLs posted:
Redirect 301 /example/ /example.php
Redirect 301 /example /example.php
Redirect directive is not really the correct directive to use here, since you need two directives to handle this. (Generally, with the
Redirect directive, you need to either include or exclude the trailing slash on both the source and target URLs.)
You could use the
RedirectMatch directive instead, which matches using a regex. For example, to handle both with and without a trailing slash:
RedirectMatch 301 ^/example/?$ /example.php
This matches only
/example/ and redirects to
RedirectMatch are both part of mod_alias.
However, if you are already using mod_rewrite then consider using mod_rewrite
RewriteRule instead to avoid potential conflicts, since mod_rewrite always runs before mod_alias, despite the apparent order of the directives in
.htaccess. For example:
RewriteRule ^example/?$ /example.php [R=301,L]
Note that there is no slash prefix on the
RewriteRule pattern when used in
.htaccess since the URL-path that the pattern matches against has had the directory-prefix (which always ends with a slash) removed.
Note also that the order of the directives within each module can be important.
Aside: If you've had your website "re-done", why are the "new" URLs of the form
/example.php? This would seem to be backward?
You could potentially keep the original WordPress URLs (eg.
/example) and internally rewrite the request to the underlying file that handles the request (ie.
example.php) instead of externally redirecting. For this you would need to use mod_rewrite. You also need to be linking to the "old" WordPress URLs in your HTML source. eg.
/example (and consider canonicalising the trailing slash - redirect to one or the other).
To internally rewrite
/example.php you simply need to remove the
R flag from the above
RewriteRule directive. For example:
RewriteRule ^example/?$ example.php [L]
(I've also removed the slash prefix on the
RewriteRule substitution, which is now not required since we are rewriting to a filesystem path.)
Providing you link to
/example in your HTML source then the user is unaware that the request is really mapped to