Reputation: 11
I am using this rule to rewrite the link
RewriteEngine On
RewriteRule ^(.*)/(.*) show_cv.php?email=$1
It is working fine like if I write this url with last slash
www.mysite.com/[email protected]/ ----> [email protected]
But when I remove the last slash from the link www.mysite.com/[email protected]/
it shows error 404.
I wish the URL Rewrite rule would work for both with slash and without slash (/
)
www.mysite.com/[email protected]/ ----> [email protected]
www.mysite.com/[email protected] ----> [email protected]
Upvotes: 1
Views: 273
Reputation: 143856
Your rules are looping, you need to make sure you are rewriting an email address, and add some conditions so that the rule doesn't get applied if it's accessing an existing resource:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9_\-\@\.]+)/?$ /show_cv.php?email=$1 [L]
Upvotes: 1
Reputation: 42885
I assume you note these rules in a .htaccess file, not in the server configuration when looking at your description ?
Rethink if you don-t want to put this into the server configuration. Apart from the usage of .htaccess files being harder to debug using rewrite rules in those files is more complex than in the server configuration. This is documented in mod_rewrites docs.
The reason for the behaviour is the different content of REQUEST_URI in both cases. Have a try checking this directly and you will see the problem. The whole part "[email protected]" is simply missing in that variable in case 2 (no "/"). To get this working you must use an additional rewriteCondition (also documented...). Something like these untested lines:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(.+)&
RewriteRule - show_cv.php?email=%1
(note the '%' instead of a '$' in the last line)
Upvotes: 0
Reputation: 1407
You should then be using the following rule:
RewriteRule ^(.*)/? show_cv.php?email=$1
Upvotes: 0