|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 Last edited by pixeline : June 3rd, 2009 at 12:06 PM. Reason: small typo |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
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:
i'll try that ! Last edited by pixeline : June 3rd, 2009 at 04:22 PM. Reason: made the link clickable |
|
#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. |
|
#7
|
|||
|
|||
|
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. ![]() |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > How to exclude html files from my rewrite? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|