Forum Moderators: phranque
I'm trying redirect links looking for images and css in the root to sub directories depending what sub directory the site is in. This /en/media/ stays the same it's the sub directories that change.
RewriteEngine on
RewriteRule /en/media/ /varible-sub-dir/en/media/ [R]
Any help please? Thanks
fintan.
If you do want to use a redirect, I suggest you use a 301 redirect, not a 302, or you won't be telling search engines to stop using the old URL.
I suspect you'll be happier if you take the requested subdomain and URL-path, and internally rewrite to a different filepath. In this way, the URL stays the same; Only the filepath used to deliver content for that URL changes.
Also, always use an [L] flag on your rules, unless you have a specific reason not to.
Jim
I'll try to explain it better.
I've 10 directories hanging off root with the same structure. Say each has a sub directory with media/images. So it would be /a/media/images, /b/media/images and so on. How would I rewrite all links that point to /media/images to point to
/a/media/images, /b/media/images, /c/media/images, etc...
depending on which directory they are in a, b, c, etc..
It's internal so I'm not that concerned about search engines.
What I've got so far is.
RewriteEngine on
# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^mydomain$
# Only apply to URLs that are under /media/images/
RewriteCond %{REQUEST_URI} ^/media/images/
This is where I fall down.
If it was something like this it'll be easy
RewriteRule /([a-z])/media/images /media/images/$1
but I need the variable on the other link like this
RewriteRule /en/media/ /a¦b¦c¦etc/en/media/
Is there a way to carry a variable from a RewriteCond and pass it into a RewriteRule?
Yes, it is a basic function of mod_rewrite. And rather than waiting around all day for an answer in a forum, it would likely be faster (and a better investment) to read the Apache mod_rewrite documentation [httpd.apache.org] -- specifically the notes in the RewriteCond and RewriteRule sections on "back-references."
Jim
Jim
[edited by: jdMorgan at 12:53 pm (utc) on June 12, 2008]