Forum Moderators: phranque

Message Too Old, No Replies

Rewrite to a single file except art

how to rewrite to a single file with exceptions

         

Pennoc

7:06 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



I'm trying to rewrite every request at a domain to a single file, with the exception of the art folder and an admin folder. Right now I'm using the following

RewriteCond %{HTTP_HOST} something.com
RewriteCond %{REQUEST_URI}!something/
RewriteRule ^(.*)$ something/test.php [L]

This correctly rewrites everything to test.php so I can read the url directly and process it internally. I've tried to but the exceptions into the regex as follows, but it dosen't work:

RewriteRule ^/(?!art\/¦stats\/)(.*)$ something/test.php [L]

I'd normally do this in the conf with an AliasMatch, but I don't have access to the conf for one of my sites hosted on an external server.

AliasMatch ^/(?!art\/¦stats\/)(.*) /home/something/public_html/test.php

Any ideas how I can use the rewrite statements above to accomplish this? Thanx

jdMorgan

7:23 pm on Aug 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{HTTP_HOST} something\.com
RewriteCond %{REQUEST_URI} !/(something¦art存tats)/
RewriteRule ^(.*)$ /something/test.php [L]

or even simpler,

RewriteCond %{HTTP_HOST} something\.com
RewriteRule !^(something¦art¦stats)/ /something/test.php [L]

Note that posting on this board modifies solid pipe characters and shows them as broken pipes "¦". You must edit them back to solid pipes before using the code.

Jim

Pennoc

8:52 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



Based on what you said I think what I need is the following. I think I forgot to mention that something.com is a parked domain and I need to rewrite all the traffic to the ./something folder, which is where the site actually resides.

RewriteCond %{HTTP_HOST} something\.com
RewriteCond %{REQUEST_URI}!something/
RewriteRule!^(art存tats)/(.*)$ something/test.php [S=1]
RewriteRule ^(.*)$ something/$1 [L]

This generates and internal server error when I use the 2 rewrite rules together. The rules work fine when run alone but fail together. This is supposed to route everything that is in /(art存tat)/* to /something/(art存tats)/* and everyting else to /something/test.php. What am I missing?

jdMorgan

10:27 pm on Aug 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Any of these variants should work:

# Rewrite all requests for something.com, except for subirs /something, /art, and /stats to /something/test.php
RewriteCond %{HTTP_HOST} something\.com
RewriteCond %{REQUEST_URI} !^/(something地rt存tats)/
RewriteRule .* /something/test.php [L]
# Rewrite /art and /stats to /something/art or /something/stats
RewriteCond %{HTTP_HOST} something\.com
RewriteCond %{REQUEST_URI} !^/something/
RewriteRule (.*) /something/$1 [L]

- or -

# Rewrite something.com/art<anything> and something.com/stats<anything> to
# something.com/something/art<anything> and something.com/something/stats<anything>, respectively
RewriteCond %{HTTP_HOST} something\.com
RewriteCond %{REQUEST_URI} !^/something/
RewriteRule ^((art存tats).*) /something/$1 [L]
# Rewrite all other resources requested from something.com to something.com/something/test.php
RewriteCond %{HTTP_HOST} something\.com
RewriteCond %{REQUEST_URI} !^/something/
RewriteRule .* /something/test.php [L]

- or -

# If requested domain is not something.com, or if /something/ subdirectory is requested, skip next 2 rules.
RewriteCond %{HTTP_HOST} !something\.com [OR]
RewriteCond %{REQUEST_URI} ^/something/
RewriteRule .* - [S=2]
# Else rewrite something.com/art<anything> and something.com/stats<anything> to
# something.com/something/art<anything> and something.com/something/stats<anything>, respectively
RewriteRule ^((art存tats).*) /something/$1 [L]
# Else rewrite all other resources requested from something.com to something.com/something/test.php
RewriteRule .* /something/test.php [L]

Be aware that RewriteConds only apply to the single RewriteRule that follows. Subsequent RewriteRules must have their own RewriteConds if needed. Example number three demonstrates one way two rules can effectively "share" RewriteConds.

All of the above examples should be functionally identical; They differ primarily in 'style' and one or the other may be better for your site in terms of expandibility and/or maintainability.

Jim