Forum
Remove + character from URL
Hi,
I have a list and details page set up where the title (a products name) becomes the slug. Problem I'm having that some of the titles have '+' characters in them which returns a 404 page.
This is my .htaccess file. Other special characters are being striped out fine.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^products/([a-zA-Z0-9-/]+)$ /details.php?s=$1 [L]
RewriteRule ^category/([a-zA-Z0-9-/]+)$ /category.php?s=$1 [L]
AddTpe application/x-httpd-php .php .htm .html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
</IfModule>
You need to add a plus to this character class:
[a-zA-Z0-9-/]
+
is a special character, so needs to be escaped e.g.Thanks Drew, this now leads me to a page (rather than a 500) but no content is pulled from the database.
Can you show me what the debug outputs for the page?
The url for this example is /products/md8+
Many thanks.
Ah ok, I see what you mean. A
+
is a special character in URLs so you'll need to encode it. You can useurlencode="true"
on a tag to URL encode it.I think generally it's going to prove a bad idea to use a
+
.Thanks Drew, still causing issues, so I think the best thing is to add a custom Slug text field to avoid the problem.
Many thanks.