Forum

Thread tagged as: Question, Problem

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>
Sarah Evans

Sarah Evans 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

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.

[a-zA-Z0-9-/\+]

Thanks Drew, this now leads me to a page (rather than a 500) but no content is pulled from the database.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me what the debug outputs for the page?


SELECT * FROM perch2_pages WHERE pagePath='/details.php' LIMIT 1 Using template: /templates/pages/attributes/default.html Using sub-template: /templates/pages/attributes/seo.html SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Products' AND (regionPage='/products.php' OR regionPage='*') SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=31 AND idx.itemRev=233)) AND ((idx.indexKey='slug' AND idx.indexValue='md8 ')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC LIMIT 0, 1 Using template: /templates/content/product_detail.html SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/details.php' OR regionPage='*' ORDER BY regionPage DESC

The url for this example is /products/md8+

Many thanks.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah ok, I see what you mean. A + is a special character in URLs so you'll need to encode it. You can use urlencode="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.