Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Help! .htaccess modification!

.htaccess mod_rewrite images pictures graphics



9:23 am on Oct 22, 2003 (gmt 0)

10+ Year Member

My original .htaccess file is the following:

RewriteRule ^catalog/(.*).html$ http://www.mydomain.com/product.php?article=$1
RewriteRule ^catalog/images/(.*)$ http://www.mydomain.com/images/$1 [L]
RewriteRule ^catalog/themes/(.*)$ http://www.mydomain.com/themes/$1 [L]
RewriteRule ^catalog/(.*)$ http://www.mydomain.com/$1 [L]

which is working.

However, up to now I used subdomain for different countries, e.g. es.mydomain.com us.mydomain.com etc.

I now added a new domain name myotherdomain.com and I want to have one simple .htaccess file to cover any domains.

RewriteRule http://(.*)/catalog/(.*).html$ http://www.mydomain.com/product.php?article=$2
RewriteRule http://(.*)/catalog/images/(.*)$ http://www.mydomain.com/images/$2 [L]
RewriteRule http://(.*)/catalog/themes/(.*)$ http://www.mydomain.com/themes/$2 [L]
RewriteRule http://(.*)/catalog/(.*)$ http://www.mydomain.com/$2 [L]

If I make the domain variable I get the pictue/image display problem again.

Do you have any suggestions?



9:24 am on Oct 22, 2003 (gmt 0)

10+ Year Member

Sorry, the new version is of course:

RewriteRule http://(.*)/catalog/(.*).html$ http://$1/product.php?article=$2
RewriteRule http://(.*)/catalog/images/(.*)$ http://$1/images/$2 [L]
RewriteRule http://(.*)/catalog/themes/(.*)$ http://$1/themes/$2 [L]
RewriteRule http://(.*)/catalog/(.*)$ http://$1/$2 [L]


9:25 am on Oct 22, 2003 (gmt 0)

10+ Year Member

do you have any suggestions?



1:51 pm on Oct 22, 2003 (gmt 0)

10+ Year Member

Welcome to WebmasterWorld.com [webmasterworld.com], jakob77!

If you're going to check for the subdomain, you should use something like this:

RewriteCond %{HTTP_HOST} !www\.mydomain\.com [NC]

Also, since you're just using the [L] tag, a more efficient way of doing things would be to remove the lookup to your domain in your substitution:

RewriteRule ^catalog/(.*)\.html$ /product.php?article=$2 [L]

I also added a backslash before .html so that you would match a dot, and not just any character.


5:20 pm on Oct 22, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member


Welcome to WebmasterWorld [webmasterworld.com]!

closed is correct -- The domain (host name) is not "visible" to RewriteRule, and RewriteCond must be used to check the domain or to create backreferences based on the domain information.

Also, you have a choice between creating an external redirect and an internal filepath substitution with mod_rewrite; When applicable, an internal rewrite is much more efficient, saving an extra HTTP "handshake" with the client browser.

ref: [httpd.apache.org...]



8:26 pm on Oct 22, 2003 (gmt 0)

10+ Year Member


Featured Threads

Hot Threads This Week

Hot Threads This Month