Reputation: 1752
I need to use the urlencode()
function which will make urls contain '%' sign.
My current rewrite does not allow these characters so i need to update it and what ive tried crashes the whole server.
Sample URL/A tag: <a href="/edit-portfolio/MQ%3D%3D">Test Link</a>
Old .htaccess
(Working great untill i needed urlencode()
)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)$ index.php?page=$1&c=$2 [NC,L]
New .htaccess
(Crashes site)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z_-%]+)/([0-9a-zA-Z_-%]+)$ index.php?page=$1&c=$ [NC,L]
Upvotes: 1
Views: 430
Reputation: 48751
You should take care of -
in a character class because it may define a range. Just to be sure escape it all the time:
RewriteRule ^([0-9a-zA-Z_\-%]+)/([0-9a-zA-Z_\-%]+)$ index.php?page=$1&c=$ [NC,L]
^ ^
[_-%]
this range isn't valid at all
or move it to the end of character class:
RewriteRule ^([0-9a-zA-Z_%-]+)/([0-9a-zA-Z_%-]+)$ index.php?page=$1&c=$ [NC,L]
By the way all could be shortened to:
RewriteRule ^([^/]+)/([^/]+)$ index.php?page=$1&c=$2 [NC,L]
^ You missed this one
Upvotes: 2