Images and css problem on the second rewrite rule

Discuss practical ways rearrange URLs using mod_rewrite.

Images and css problem on the second rewrite rule

Postby enovar » Thu Jul 03, 2008 9:29 am

Hello

i have this htaccess:

#################################################
<Files ~ "^.(htaccess|htpasswd)$">
deny from all
</Files>
ErrorDocument 404 http://mydomain.com
order deny,allow


Options +FollowSymLinks
RewriteEngine On


RewriteCond $1 !^(index\.php|style.css|img\.png|includes|SpryAssets|Connections)
RewriteRule ^([^/]*)$ index.php?doc=$1 [L]

RewriteRule ^([^/]*)/([^/]*)$ index.php?doc=$1&item=$2 [L]
###############################################

Every thing works ok on the first rewrite (images and css)
like:
http://mydomain.com/test (htaccess)
http://mydomain.com/index.php?doc=test (real)

But if i do this i lost my css ans images:
http://mydomain.com/test/whatever (htaccess)
http://mydomain.com/index.php?doc=teste&item=whatever (real)

Any ideias, anyone can help me?

Thank´s in advance
enovar
 
Posts: 6
Joined: Thu Jul 03, 2008 9:19 am

Postby richardk » Fri Jul 04, 2008 2:26 pm

richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Friendly URLs with Mod_Rewrite

Postby enovar » Mon Jul 07, 2008 2:57 am

Hello,

I already tried the instructions on the F.A:Q ( Relative paths to images, JavaScript, CSS and other external/linked files are broken.), but didn't work.

Anyone has clue or an ideia to get it work.

Thank´s in Advance
enovar
 
Posts: 6
Joined: Thu Jul 03, 2008 9:19 am

Postby richardk » Mon Jul 07, 2008 1:58 pm

My mistake, try
Code: Select all
<Files ~ "^\.(htaccess|htpasswd)$">
Deny from all
</Files>

ErrorDocument 404 http://mydomain.com
Order deny,allow
Options +FollowSymLinks

RewriteEngine On

# Files to ignore.
RewriteRule ^index\.php|style.css|img\.png$ - [L]

# Directories to ignore.
RewriteRule ^(includes|SpryAssets|Connections)(/.*)?$ - [L]

RewriteRule ^([^/]+)$         /index.php?doc=$1         [L]
RewriteRule ^([^/]+)/([^/]+)$ /index.php?doc=$1&item=$2 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Friendly URLs with Mod_Rewrite

Postby enovar » Tue Jul 08, 2008 2:20 am

Hello again,

Thank´s you for your effort, but it still fail the images and css on the second rewrite rule.

I made a change to work on the first rewrite rule

<Files ~ "^\.(htaccess|htpasswd)$">
Deny from all
</Files>

ErrorDocument 404 http://mydomain.com
Order deny,allow
Options +FollowSymLinks

RewriteEngine On

# Files to ignore.
RewriteRule ^index\.php|style.css|img(I delete here) - [L]

# Directories to ignore.
RewriteRule ^(includes|SpryAssets|Connections)(/.*)?$ - [L]

RewriteRule ^([^/]+)$ /index.php?doc=$1 [L]
RewriteRule ^([^/]+)/([^/]+)$ /index.php?doc=$1&item=$2 [L]

On the second rewrite rule i think that the problem is because he gets this url: http:mydomain.com/test/whatever

and the image/css get this url:
http://mydomain.com/test/img/image.png
http://mydomain.com/test/style.css

And would it be:
http://mydomain.com/img/image.png
http://mydomain.com/style.css

Thank´s in advance
enovar
 
Posts: 6
Joined: Thu Jul 03, 2008 9:19 am

Postby richardk » Wed Jul 09, 2008 1:53 pm

I made a change to work on the first rewrite rule

Don't. Add it to the line below specifically for directories.
Code: Select all
<Files ~ "^\.(htaccess|htpasswd)$">
Deny from all
</Files>

ErrorDocument 404 http://mydomain.com
Order deny,allow
Options +FollowSymLinks

RewriteEngine On

# Files to ignore.
RewriteRule ^index\.php|style.css$ - [L]

# Directories to ignore.
RewriteRule ^(includes|SpryAssets|Connections|img)(/.*)?$ - [L]

RewriteRule ^([^/]+)$         /index.php?doc=$1         [L]
RewriteRule ^([^/]+)/([^/]+)$ /index.php?doc=$1&item=$2 [L]


On the second rewrite rule i think that the problem is because he gets this url: http:mydomain.com/test/whatever

and the image/css get this url:
/test/img/image.png
/test/style.css

And would it be:
/img/image.png
/style.css

Then it is a relative URL problem as well.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Friendly URLs with Mod_Rewrite

Postby enovar » Fri Jul 11, 2008 2:57 pm

Hello richardk,

You are right, after your tips, at the end it was in fact a url relative problem. Now everything is working just fine, like i expected and You.

Let me say that htaccess is very powerful, but in same time it's so sensitivity.
Like my girlfriend. lol :)
I´m glad that you open this forum. If it wasn´t your forum i already give up to other hard solution.

Thank´s for everything richardk and thank´s again for your very serious work. You really did my day.

Many Hapiness for you. Your way of thinking is what we need for our world.


Take care
From Portugal
Enovar
enovar
 
Posts: 6
Joined: Thu Jul 03, 2008 9:19 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 94 guests

cron