|
Home > Archive > Apache Server configuration support > September 2007 > mod_rewrite & css
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| design@scottconnery.com 2007-09-20, 1:33 pm |
| I want my URI to be rewritten from www.mywebsite.com/design/A/B to
www.mywebsite.com?set=A/B
This htaccess script redirect the page requests properly
Options +Indexes
RewriteEngine on
#RewriteBase /
RewriteRule ^design/(.*) design.php?set=$1[L]
However the css and image files do not show up. According to a
debugger I use, one error is that the css is being served as text/
html, not text/css. I think the file equest is being converted to
www.mywebsite.com?set=css/main.css.
I have tried
Options +Indexes
RewriteEngine on
AddType application/x-shockwave-flash .swf
AddType image/x-icon .ico
AddType text/css .css
#RewriteBase /
RewriteRule ^design/(.*) design.php?set=$1
to force the file types and tried
Options +Indexes
RewriteEngine on
AddType application/x-shockwave-flash .swf
AddType image/x-icon .ico
AddType text/css .css
#RewriteBase /
RewriteRule ^.+(/css/main\.css)$ $2
RewriteRule ^design/(.*) design.php?set=$1 [L]
to escape the css files from the rewrite, however the css still will
not show up.
| |
| David McKenzie 2007-09-21, 1:32 am |
| design@scottconnery.com wrote:
> I want my URI to be rewritten from www.mywebsite.com/design/A/B to
> www.mywebsite.com?set=A/B
>
> This htaccess script redirect the page requests properly
>
> Options +Indexes
> RewriteEngine on
> #RewriteBase /
> RewriteRule ^design/(.*) design.php?set=$1[L]
>
> However the css and image files do not show up. According to a
> debugger I use, one error is that the css is being served as text/
> html, not text/css. I think the file equest is being converted to
> www.mywebsite.com?set=css/main.css.
>
> I have tried
>
> Options +Indexes
> RewriteEngine on
> AddType application/x-shockwave-flash .swf
> AddType image/x-icon .ico
> AddType text/css .css
> #RewriteBase /
> RewriteRule ^design/(.*) design.php?set=$1
>
> to force the file types and tried
>
> Options +Indexes
> RewriteEngine on
> AddType application/x-shockwave-flash .swf
> AddType image/x-icon .ico
> AddType text/css .css
> #RewriteBase /
> RewriteRule ^.+(/css/main\.css)$ $2
> RewriteRule ^design/(.*) design.php?set=$1 [L]
>
> to escape the css files from the rewrite, however the css still will
> not show up.
>
Where's the CSS file located?
--
DM davidm@cia.com.au
'It would go against respecting principles and truth if you have to
respect and accept anything just because it is the other side's view.'
- Kim Jung Ill
| |
|
| On Sep 21, 12:28 am, David McKenzie <dav...@cia.com.au> wrote:
> des...@scottconnery.com wrote:
>
>
>
>
>
>
>
>
>
> Where's the CSS file located?
>
> --
> DM dav...@cia.com.au
>
> 'It would go against respecting principles and truth if you have to
> respect and accept anything just because it is the other side's view.'
> - Kim Jung Ill
The css file is located at
Root\css\main.css
the .htacess file is at the root as is the script.
| |
| Jim Hayter 2007-09-21, 1:28 pm |
| Scott wrote:
<snip>[vbcol=seagreen]
What is this rule supposed to do? You are rewriting to $2 but there is
no second parenthesized expression in the line.
[vbcol=seagreen]
Jim
| |
|
| "Scott" <design@scottconnery.com> schreef in bericht
news:1190378482.554481.166480@57g2000hsv.googlegroups.com...
> The css file is located at
> Root\css\main.css
> the .htacess file is at the root as is the script.
>
If I understand you correctly, that's like
document_root/
document_root/.htaccess
document_root/design.php
document_root/design/
document_root/css/
document_root/css/main.css
In .htaccess there is no need to exclude some URIs from being rewritten,
unless the resource is below the current folder.
In .htaccess the URI '/css/main.css' is left hand trimmed before processing
to 'css/main.css' and will consequently never match 'RewriteRule
^.+(/css/main\.css)$ $1'. This rule will match on '/design/css/main.css' and
so will the other rule!
The documented syntax for not-rewritting is
RewriteRule regex-to-match-this - [L]
Is your stylesheet linked like this
<link rel="stylesheet" type="text/css" href="../main.css">
than try
<link rel="stylesheet" type="text/css" href="/css/main.css">
For further comment show me the <img ...> tag for a failing image, along
with the URL of the page referring and full local path of both the image and
the html file.
HansH
| |
|
| On Sep 21, 3:36 pm, "HansH" <ha...@invalid.invalid> wrote:
> "Scott" <des...@scottconnery.com> schreef in berichtnews:1190378482.554481.166480@57g2000hsv.googlegroups.com...>> > RewriteRule ^.+(/css/main\.css)$ $2
>
>
>
>
> If I understand you correctly, that's like
> document_root/
> document_root/.htaccess
> document_root/design.php
> document_root/design/
> document_root/css/
> document_root/css/main.css
>
> In .htaccess there is no need to exclude some URIs from being rewritten,
> unless the resource is below the current folder.
>
> In .htaccess the URI '/css/main.css' is left hand trimmed before processing
> to 'css/main.css' and will consequently never match 'RewriteRule
> ^.+(/css/main\.css)$ $1'. This rule will match on '/design/css/main.css' and
> so will the other rule!
>
> The documented syntax for not-rewritting is
> RewriteRule regex-to-match-this - [L]
>
> Is your stylesheet linked like this
> <link rel="stylesheet" type="text/css" href="../main.css">
> than try
> <link rel="stylesheet" type="text/css" href="/css/main.css">
>
> For further comment show me the <img ...> tag for a failing image, along
> with the URL of the page referring and full local path of both the image and
> the html file.
>
> HansH
The structure looks like this:
document_root/
document_root/.htaccess
document_root/design.php
document_root/css/
document_root/css/main.css
document_root/images
The style sheet request is
<LINK href="css/text-main.css" type=text/css rel=stylesheet>
the image call is
<DIV class=mainWindow <?php echo "style='BACKGROUND: url(images/BG".
$page.".jpg) no-repeat'"?>>
aka:
<DIV class=mainWindow style='BACKGROUND: url(images/BGimage.jpg) no-
repeat'"?>
What I would like to do is redirect every call to design.php and set
the query string except those within the images or css directories
| |
|
| "Scott" <design@scottconnery.com> schreef in bericht
news:1190723524.848095.133070@22g2000hsm.googlegroups.com...
> The structure looks like this:
> document_root/
> document_root/.htaccess
> document_root/design.php
> document_root/css/
> document_root/css/main.css
> document_root/images
>
> The style sheet request is
> <LINK href="css/text-main.css" type=text/css rel=stylesheet>
After requesting '/design/page.html' the stylesheet requested is
'/design/css/text-main.css' -check your logs-
Try
<LINK href="/css/text-main.css" type=text/css rel=stylesheet>
> the image call is
> <DIV class=mainWindow <?php echo "style='BACKGROUND:
> url(images/BG".$page.".jpg) no-repeat'"?>>
At first sight the same leading slash should again save the day.
However, images included in style attributes most likely adhere to
http://www.w3.org/TR/CSS1#url: 'Partial URLs are interpreted relative
to the source of the style sheet, not relative to the document:'
Here a partial URL is any URL NOT starting http:, just a leading /
will NOT bring you to the root of the site!
Try
<?php echo "style='BACKGROUND: url(../images/BG".$page.".jpg)"?>>
adding an additional '../' prefix for each virtual folders below /design.
Alternatively
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^design(/|/.*/)(css|images)/(.*) /$2/$3 [L]
before
RewriteRule ^design/(.*\.html?) design.php?set=$1 [L]
should -as in untested- make mislocated requests for stylesheets and
images read the intended stylesheet or image. The RewriteCond
enables per folder alternates, turning /css.* and /images/*. into globals.
> What I would like to do is redirect every call to design.php and set
> the query string except those within the images or css directories
Either I do not understand you're writings or ...
If you redirect every request, your script will have to pass images too
AND set the content header according to each image type.
Rather limit the parsable requests to .htm(l)
RewriteRule ^design/(.*\.html?)$ design.php?set=$1 [L]
Note the trailing l is optional.
BTW, in general handling .htaccess will give some overhead to the server
reducing performance. To keep this penalty to a minimum move the rewrite
directives from /.htacess to /design/.htaccess and alter them slightly:
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?(css|images)/(.*) $2/$3 [L]
RewriteRule ^(.*\.html?) design.php?set=$1 [L]
It'll save the time to process the directives for each request outside this
branch.
HansH
|
|
|
|
|