Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 3rd, 2009, 12:05 PM
pixeline's Avatar
pixeline pixeline is offline
King of RGB
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: brussels
Posts: 398 pixeline User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 1 m 52 sec
Reputation Power: 6
How to exclude html files from my rewrite?

hi!

i want to redirect some urls, but not those that do end with ".html"

I tried this:

Code:
RewriteCond %{REQUEST_URI} !^/(_admin|_css|_js|_img|_phpmyadmin)/.*$ [NC]
RewriteCond %{REQUEST_URI} !^\.(html|htm)$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&%{QUERY_STRING} [L]


but accessing "domain.com/projects/by_time.html" redirects to "domain.com"

Why is that?

Thanks,

Alexandre
__________________
http://www.pixeline.be
........................................

Last edited by pixeline : June 3rd, 2009 at 12:06 PM. Reason: small typo

Reply With Quote
  #2  
Old June 3rd, 2009, 01:10 PM
Sarah_S Sarah_S is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 197 Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Days 54 m 11 sec
Reputation Power: 275
Hello again,

> RewriteCond %{REQUEST_URI} !^\.(html|htm)$ [NC]
Please make note of the "^", marking the beginning of the string.
Does it work properly if you remove the "^"?

Last edited by Sarah_S : June 3rd, 2009 at 01:15 PM.

Reply With Quote
  #3  
Old June 3rd, 2009, 02:14 PM
pixeline's Avatar
pixeline pixeline is offline
King of RGB
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: brussels
Posts: 398 pixeline User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 1 m 52 sec
Reputation Power: 6
Hello Again Sarah!

in fact i needed to make sure my rewriting allowed access to physical html files. This rule is better for that:

Code:
RewriteCond %{REQUEST_FILENAME} !-f


I have a question though, regarding rewriteCond:

is it possible to have one rewriteCond apply for several rewriteRule, or do i have to repeat the same Condition for several rules?

See, here is my htaccess file. In order to make it more readable, i'd like to combine them all.

Code:
# Externally redirect to add missing trailing slash

RewriteRule ^(([a-z0-9._\-]+/)*[a-z0-9_\-]+)$ http://%{HTTP_HOST}/$1/?%{QUERY_STRING} [NC,R,L]


# SIX PARAMS
RewriteCond %{REQUEST_URI} !^/(_admin|_css|_js|_img|_phpmyadmin)/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4&id=$5&title=$6&%{QUERY_STRING} [L]

# FIVE  PARAMS
RewriteCond %{REQUEST_URI} !^/(_admin|_css|_js|_img|_phpmyadmin)/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4&id=$5&%{QUERY_STRING} [L]

# FOUR PARAMS
RewriteCond %{REQUEST_URI} !^/(_admin|_css|_js|_img|_phpmyadmin)/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4&%{QUERY_STRING} [L]

# THREE PARAMS : projects/touch/texts/
RewriteCond %{REQUEST_URI} !^/(_admin|_css|_js|_img|_phpmyadmin)/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&%{QUERY_STRING} [L]

# TWO PARAMS: downloads
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^downloads/([a-z0-9._\-]+)/$ index.php?section=downloads&item=$1&%{QUERY_STRING}  [L]

# TWO PARAMS:
RewriteCond %{REQUEST_URI} !^/(_admin|_css|_js|_img|_phpmyadmin)/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&%{QUERY_STRING} [L]

# TAG URL : index.php?tag=space%2C+navigable+music#5
RewriteCond %{REQUEST_URI} !^/(_admin|_css|_js|_img|_phpmyadmin)/.*$ [NC]

RewriteRule ^tag/([a-z0-9_\-]+)/$ index.php?tag=$1&%{QUERY_STRING} [L]
# ONE PARAM
RewriteCond %{REQUEST_URI} !^/(_admin|_css|_js|_img|_phpmyadmin)/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z0-9_\-]+)/$ index.php?section=$1&%{QUERY_STRING} [L]


if you have any suggestion to make it less repetitive, i'm all ears

Thank you,

Alexandre

Reply With Quote
  #4  
Old June 3rd, 2009, 02:54 PM
Sarah_S Sarah_S is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 197 Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Days 54 m 11 sec
Reputation Power: 275
Yes, I think you can use the "C" flag to chain the rule with the next one (do it as many times as you need to), making the condition apply for the rules in that chain.
Code:
RewriteCond ...
RewriteRule ... [C,...]
RewriteRule ... [C,...]
RewriteRule ...

Last edited by Sarah_S : June 3rd, 2009 at 02:57 PM.

Reply With Quote
  #5  
Old June 3rd, 2009, 03:32 PM
pixeline's Avatar
pixeline pixeline is offline
King of RGB
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: brussels
Posts: 398 pixeline User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 1 m 52 sec
Reputation Power: 6
I did some research on the C flag (which means "chain") and it would actually combine the rules, which does not make sense to me if you also use the L flag, meaning, "stop reading".

So i found this: http://my.galagzee.com/index.php/20...y-rewriterules/

Quote:

Turns out there is a fairly simple trick to achieve exactly what I was looking for: if the RewriteCond is negated and followed by RewriteRule . - [S=n] to skip following n rules, the RewriteRules in essence are only applied when the singular RewriteCond is true. Like so:


RewriteCond %{REQUEST_URI} !^/(pattern1|pattern2|pattern3)(/[0-9]+|/P[0-9]+|)[/]?$ [NC]
RewriteRule . - [S=3]
RewriteRule ^/([^/]*)[/]?$ /index.php/site_embeds/department/$1/X [L]
RewriteRule ^/([^/]*)/([0-9]+)[/]?$ /index.php/site_embeds/article/$2/$1 [L]
RewriteRule ^/([^/]*)/P([0-9]+)[/]?$ /index.php/site_embeds/department_archive/P$2/$1 [L]

Now the last three rules are skipped if the condition is not true or, in reverse: they are applied if the condition is true.



i'll try that !

Last edited by pixeline : June 3rd, 2009 at 04:22 PM. Reason: made the link clickable

Reply With Quote
  #6  
Old June 3rd, 2009, 03:58 PM
pixeline's Avatar
pixeline pixeline is offline
King of RGB
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: brussels
Posts: 398 pixeline User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 1 m 52 sec
Reputation Power: 6
It works, check this out !

Code:
# Externally redirect to add missing trailing slash
RewriteRule ^(([a-z0-9._\-]+/)*[a-z0-9_\-]+)$ http://%{HTTP_HOST}/$1/?%{QUERY_STRING} [NC,R,L]

RewriteCond %{REQUEST_URI} ^(_admin|_css|_js|_img|_phpmyadmin)/.*$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [S=8]

# SIX PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4&id=$5&title=$6&%{QUERY_STRING} [L]

# FIVE  PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4&id=$5&%{QUERY_STRING} [L]

# FOUR PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4&%{QUERY_STRING} [L]

# THREE PARAMS : projects/touch/texts/
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&%{QUERY_STRING} [L]

# TWO PARAMS: downloads
RewriteRule ^downloads/([a-z0-9._\-]+)/$ index.php?section=downloads&item=$1&%{QUERY_STRING}  [L]

# TWO PARAMS:
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&%{QUERY_STRING} [L]

# TAG URL : index.php?tag=space%2C+navigable+music#5
RewriteRule ^tag/([a-z0-9_\-]+)/$ index.php?tag=$1&%{QUERY_STRING} [L]
# ONE PARAM
RewriteRule ^([a-z0-9_\-]+)/$ index.php?section=$1&%{QUERY_STRING} [L]


Sarah, thank you for your continued help. You did not provide the answer but you lead me to it by your suggestion. Thanks !

A.

Reply With Quote
  #7  
Old June 3rd, 2009, 04:03 PM
Sarah_S Sarah_S is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 197 Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level)Sarah_S User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Days 54 m 11 sec
Reputation Power: 275
Okay. I was not aware of the "S" (skip) flag, so I need to look more into that.
Sorry I could not really help you much, but you figured it out, so that is great.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > How to exclude html files from my rewrite?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
Stay green...Green IT