Using ModRewrite
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Using ModRewrite
Using ModRewrite
21-12-2009 8:54 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I've had a quick trawl through previous postings in the hope that this would be a FAQ, but I couldn't see anything obviously related. Can anybody suggest what I might be doing wrong?
Re: Using ModRewrite
23-12-2009 9:47 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: Using ModRewrite
23-12-2009 10:23 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
# If the domain is [www.]mydomain[...]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain [nc]
# ... then re-write the URL to point at the corresponding folder on the CCGI server
RewriteRule ^(.*)$ http://ccgi.myaccount.plus.com/mydomain/$1
The browser shows the expected content, but the address bar shows the plus.com URLs instead of http://mydomain URLs.
Re: Using ModRewrite
23-12-2009 11:15 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Try something like
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.co\.uk$ [nc]
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) /folder/$1
Gabe
Re: Using ModRewrite
24-12-2009 10:30 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
The code you supplied seems to be working fine with just one wrinkle that I've noticed so far, and that's a difference in behaviour with and without a trailing slash on a folder name. Given inputs of:
- mydomain/foo/
- mydomain/foo
... both correctly deliver the content. However, whereas the first (with the trailing slash) shows in the address bar as typed, the second displays as:
mydomain/domainfolder/foo/
... which is how things are organised on the server, but I want it to appear as it does when the trailing slash is supplied.
Any ideas?
Steve.
Re: Using ModRewrite
24-12-2009 11:08 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/folder/?
RewriteRule (.*) /folder/$1
It's very similar but subtly different.
Re: Using ModRewrite
24-12-2009 2:48 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: Using ModRewrite
24-12-2009 5:46 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
RewriteCond %{REQUEST_FILENAME} -dGabe
RewriteRule ^(.+[^/])$ $1/
Re: Using ModRewrite
25-12-2009 4:50 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Thanks for the input - and, of course, Merry Christmas!
Steve.
Re: Using ModRewrite
27-12-2009 5:00 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Try:
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
Gabe
Re: Using ModRewrite
28-12-2009 12:05 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I'm struggling to understand how it works though. The RewriteRule seems unchanged, and if I understand the regex it's just capturing anything without a trailing slash and adding one. So far so good. Unless I've missed something important, the only difference between your two versions is the RewriteCond that limits this rule, changing from %{REQUEST_FILENAME} -d to %{REQUEST_URI} !^.*/[^/]+\.[^/]+$. The first one was restricting the rule to directories, I believe, and that seems sensible - but it evidently didn't work as expected. The second seems to match something with a single slash, followed by at least one non-slash, followed by anything and ending in at least one non-slash. I'm not sure if I've got that quite right but, whether I have or not, I don't understand why it's needed or why the first version didn't work.
I'm currently trying to build on your solution by adding some of the nice tricks that I've read are achievable with mod_rewrite, such as /foo/bar -> /foo/BarPage.php or whatever. I rather thought such things would be straightforward once you had got me started, but I'm not finding it that easy at all. Depending on where I insert my rule (and possibly whether or not I use
Re: Using ModRewrite
29-12-2009 1:50 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator

The reason for the trailing-slash problem is that a directory without a trailing slash is just wrong and mod_dir will try to fix that by redirecting to the canonical url (which contains the directory you don't want to see). The rewrite aims to add the missing slash before mod_dir does it for you and reveals all.
We don't want to add a slash to files, so the condition checks that the REQUEST_URI doesn't (the !) match a pattern starting with any or no string followed by a slash, followed by one or more characters that are not slashes, followed by a dot (it's escaped), followed by one or more characters that are not slashes (like a file extension). It's not a precise pattern, but sufficient to differentiate.
You and me both. There's always something to bite you, usually involving an infinite loop.
Gabe
Re: Using ModRewrite
31-12-2009 10:52 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page