homepage Welcome to WebmasterWorld Guest from 54.147.248.118
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
rewriteRule directive problem
server specificities
skylla

5+ Year Member



 
Msg#: 3249218 posted 1:42 pm on Feb 11, 2007 (gmt 0)

I have been trying for some time to compose a generic rewriteRule in .htaccess for a site hosted on a university server - one for which I have absolutely no control what-so-ever, except for a specific folder accessible with the URL say [uni.ac.uk...]

this is what I am trying to achieve:

[uni.ac.uk...] -> [uni.ac.uk...]

The rewrite is relatively simple and works on two servers I have tried this on except the above:


RewriteRule \.(xmltxtpnggifjpgcss)$^index.php$ - [S=1]
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L]

However, what seems to work is:


rewriteRule ^([^/]+)/$ http://uni.ac.uk/lab/new/index.php?page=$1 [L]

Note that I have not been able to:
- exempt for xml,txt,css, etc etc files,
- use the '?' or '*' quantifier to designate the absence of a trailing slash (!)
- designate index.php as the substitution string unless preceded by the complete URL.

I do realise that the rewrite is per-directory based and that the server will have its own rules too. I now know what works and what not works but have not been able to progress from here for some days. Any help is much appreciated in this matter.

S.

 

sabai

10+ Year Member



 
Msg#: 3249218 posted 6:07 pm on Feb 11, 2007 (gmt 0)

exempt for xml,txt,css, etc etc files,

Put this before your rewrite rule - it will exclude existing files and directories.

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d

For the rest of your problems, you'll just need to practise you regular expressions :-)

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3249218 posted 6:27 pm on Feb 11, 2007 (gmt 0)

Be aware that checking each and every HTTP request for "file exists" and "directory exists" as suggested above is expensive in terms of server resources. I recommend that you avoid this technique if at all possible, or make those checks conditional on a RewriteRule pattern match or on preceding RewriteCond pattern matches.

On the original subject, where is this code located? Is it located in example.com/.htaccess or in example.com/lab/.htaccess?

Jim

skylla

5+ Year Member



 
Msg#: 3249218 posted 7:02 pm on Feb 11, 2007 (gmt 0)

thanks for looking into this.

I should be able to exempt redirects on extension as far as I know, which in my opinion is the most efficient way. Re. regular expressions, they're both practised and practiced.

Since I only have limited access to the server, I can only drop files into www.example.com/lab/ where index.php is found as well.

skylla

5+ Year Member



 
Msg#: 3249218 posted 7:04 pm on Feb 11, 2007 (gmt 0)

...and that is where my .htaccess code is located as well. ;)

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3249218 posted 7:21 pm on Feb 11, 2007 (gmt 0)

Let's try a slightly-different approach, then:

Options -MultiViews
#
RewriteCond $1 !\.(xmltxtpnggifjpgcss)$
RewriteCond $1 !index\.php$
RewriteRule ^(([^/]+/)*[^/]+)/?$ /lab/index.php?page=$1 [L]

The option to disable multiviews may help with your trailing-slash problem, and the modified RewriteRule pattern may help if any files are located in subdirectories of /lab/

Replace all broken pipe "" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

If this does not help, please tell us what specific error messages you get, or any information about the server response that may be of diagnostic use; It's difficult to diagnose problems without a description of the symptoms. Also if possible, please report the contents of the server error log file when testing the code.

Jim

skylla

5+ Year Member



 
Msg#: 3249218 posted 10:13 pm on Feb 11, 2007 (gmt 0)

That's a hole in one! And only seems to work with multiviews disabled. Very strange they were enabled in the first place. Not something I would have considered looking into straight away..

Fantastic. Thanks a bunch.

S.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved