cancel
Showing results for 
Search instead for 
Did you mean: 

mod_rewrite revisited

Boxersoft
Rising Star
Posts: 132
Thanks: 20
Fixes: 1
Registered: ‎25-07-2009

mod_rewrite revisited

I have a domain hosted by PlusNet and pointing at the ccgi server, and I want to use mod_rewrite directives in .htaccess to point at a domain-specific subdirectory.
Thanks to previous assistance in here I had this working with the following:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^.*/[^/]+\.[^/]+$
RewriteRule ^(.+[^/])$ $1/ [R,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) /folder/$1

However, it seems not to be working now and is raiseing:
[tt]Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.[/tt]
It's a while since I looked at it, so I'm wondering if it's perhaps a difference in the new ccgi platform?
I've installed WAMP on my own machine to try to track the problem down, but it seems to work as expected there. Any suggestions on how to fix it, or tips on how to debug such problems?
5 REPLIES 5
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: mod_rewrite revisited

The last 3 lines are probably looping on new ccgi.
I think the line
RewriteCond %{REQUEST_URI} !^/folder/

needs to be
RewriteCond %{REQUEST_URI} !^/~username/folder/

See here.
David
Boxersoft
Rising Star
Posts: 132
Thanks: 20
Fixes: 1
Registered: ‎25-07-2009

Re: mod_rewrite revisited

Excellent - thanks very much, that seems to have fixed it. In doing that I screwed something else up somewhere such that, in a subdirectory below /folder,  referenced files don't seem to be properly rewritten so .css isn't working etc. I'll have a trawl, but if this is a common 'gotcha' with a simple solution, a pointer in the right direction would be most appreciated Smiley
Thanks again.
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: mod_rewrite revisited

I suspect the presence of /~username might be upsetting things here too. Is it PHP code that is generating the subdirectory references?
David
Boxersoft
Rising Star
Posts: 132
Thanks: 20
Fixes: 1
Registered: ‎25-07-2009

Re: mod_rewrite revisited

No, the pages I've looked at so far have just been plain HTML files with simple references, e.g.:
link href="styles.css"
form action="search.php"

... etc.
Boxersoft
Rising Star
Posts: 132
Thanks: 20
Fixes: 1
Registered: ‎25-07-2009

Re: mod_rewrite revisited

Hmmm... I've got it working now. The problem turns out to have been with another .htaccess file I have in the subdirectory so was nothing to do with the ~username change. I was rewriting a filename for backward-compatibility, but I seem to need to redirect in order to get the css files etc. to work:

RewriteCond %{REQUEST_URI} oldname/$ [nc]
# RewriteRule .* newname.htm   // Works, but unqualified links to other files in same directory fail
RewriteRule .* newname.htm [R,L]  // Works, and links are honoured

Out of interest, can anyone explain to me why it has to be a Redirect in order to work? It's not really important in this case, but it could be in other cases where I might not want to have the actual URL appear in the browser's address bar.