views:

275

answers:

2

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.

A: 

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

balpha
the rewrite rules are in a .htaccess in the ask folder, without a RewriteBase applied, so they will "strip the local directory before processing" (as documented here: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritebase)I tried your suggestion anyway, with the result still being 404 for the troublesome links.
rwired
Even if (.*) matches nothing, it's still a group, so $2 and $3 should be right. On the other hand: Are you sure that at the time of applying the RewriteRule, the string still has a slash before title|id ? If not, it won't be matched. BTW: Note that I'm not a .htaccess guru, so I might be making wrong assumptions all over the place.
balpha
+1  A: 

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.

rwired