rwired
rwired

Reputation: 1133

Why does a hyphen in a RewriteRule break when in a sub-folder

I have a bunch of RewriteRules in .htaccess for SEO purposes. Sample...

RewriteEngine On 
RewriteRule ^signup$ /signup.php
RewriteRule ^account$ /account.php
RewriteRule ^logout$ /logout.php
RewriteRule ^login$ /login.php
RewriteRule ^recent-questions$ /recent.php
RewriteRule ^popular-questions$ /popular.php
...
...
 (more similar stuff)
...
...
RewriteRule ^(.*)/([-_~*a-zA-Z0-9]+)\|([0-9]+)(\/)?$ view.php?title=$1&id=$2&%{QUERY_STRING}
RewriteRule ^([-_~*a-zA-Z0-9]+)(\/)?$ categories.php?key=$1

The system is in a sub-folder "ask" on the server.

They all work fine if I map the folder to http://ask.mydomain.com

But I don't want to use a sub-domain since I'm adding an existing header & footer managed by other people that share resouces and contains relative links with the main www. website.

When I try to access the folder via http://www.mydomain.com/ask the RewriteRules with hyphens in them result in 404 errors - the other ones continue to work.

I've already tried escaping the hyphens as - and %2D. The former made no difference. The latter takes me to a completely incorrect page.

Upvotes: 0

Views: 1691

Answers (2)

rwired
rwired

Reputation: 1133

Solution -- It wasn't the hyphens at all.

It was because MultiViews was enabled for www. domains, but not for ask. domains

/signup would map to /signup.php with MultViews default behavior,

but

/recent-question doesn't map to recent.php

Under the ask. subdomain the URL rewrites in .htaccess where being processed correctly. But MultiViews was breaking it under the www. domain.

Upvotes: 1

balpha
balpha

Reputation: 50948

To me, you seem to be replacing with the wrong groups:

RewriteRule ^(.*)/([-_~*a-zA-Z0-9]+)\|([0-9]+)(\/)?$ view.php?title=$2&id=$3&%{QUERY_STRING}

should do if I understand correctly that your URLS have the form mydomain.com/bla/title|id

Upvotes: 0

Related Questions