apache mod-rewrite file name change - mod-rewrite

This is probably straight forward for someone who know apache mod rewrite and regex but that someone is not me.
This is what I am looking for :
I just want to re-route image,css requests to one shared repository image/css file. e.g. we have 6-7 sites which can be on same server or different.
Currently, image looks like this /img/site1_header.jpg, all I want is that internally this request should become /img/header.jpg so basically remove the variable 'site1' (or site2,site 3)
Any help appreciated.
thanks

I haven't tested it, but I expect it will look something like:
RewriteEngine On
RewriteRule ^(.*)/(site[0-9]*_)(.*)$ $1/$2 [PT,L]

Related

Multiple URLs for magento store?

Quick question-
Noticed a problem on my Magento 1.7. Consider the site http://www.seacadetshipsstore.com/magento/. This site has a sub-store that's /magento/gearlocker/. The two should be isolated - if you go to /magento/gearlocker/, you shouldn't interact with the generic store at /magento/ at all.
Here's the problem: the store's base URL is set explicitly to http://www.seacadetshipsstore.com/magento/gearlocker/. When users navigate to http://seacadetshipsstore.com/magento/gearlocker/ (no www), they get redirected to http://www.seacadetshipsstore.com/magento/.
My question is this: if a user navigates to the gearlocker site without www, is there a way to set a second store URL to prevent a redirect? Or would it be easier to control that redirect back to /magento/gearlocker/, instead of /magento/? Any thoughts, solutions, or references would be greatly appreciated. Thanks!
See my comments above. Thanks #CodeMoose
RewriteEngine On
RewriteCond %{HTTP_HOST} ^seacadetshipsstore.com
RewriteRule (.*) http://http://www.seacadetshipsstore.com/magento/$1 [R=301,L]
If I remember correctly I believe duplicate urls across multiple stores are not possible without one of the urls being auto incremented with a -1 -2 etc. Please try modifying one of the url keys and let me know what happens.

mod_rewrite issue

I have some old files that need to point to new files - the old files are indexed from Google like this: old%20file%20here.pdf - because the last people doing the site left spaces in file names - but in my Rewrites they just aren't matching the old file to send to the new - does anyone know how to ignore the %20 and redirect right?
My rewrite code here:
RewriteRule ^downloads/old%file%20here.pdf$ http://www.domain.co.uk/new-file.pdf [R=301,L]
Its working fine for rest of redirects which are pages with normal URLs.
found the answer, this is it
[space]name (so should be \ name) instead of what i was doing which was \%20name
hope this helps any one else!

Exclude a directory from a rewriterule using ISAPI rewrite 3

Basically I've recently added the below rule in my httpd.conf for ISAPI rewrite on an IIS server to make sure that it always defaults to lower-case file and directory names.
RewriteRule ^(.*[A-Z].*)$ $1 [CL,R=301,L]
This is all fine and dandy for every part of the site except for one directory which we can call /MisbehavingDir, the code in this particular directory is filled with mixed-case filenames and lots of server- and client-side scripting that would have to be rewritten to use all lower-case in order to work properly (with the RewriteRule above it seems to hit a couple of 301s in the wrong places which causes that part of the site to function poorly to say the least).
Since I'm not in the mood for rewriting that part of the site I'd love to find a good way to modify the above regex so that it matches everything except paths starting with MisbehavingDir and since my regex-fu isn't really good enough I figured I'd ask here.
Is there a simple "beautiful" solution to this that anyone wants to share or should I just set aside several days to rewrite the app, then test it and go through that whole dance?
Well, apparently the trick was to add a rewritecond statement that looks something like RewriteCond %{URL} ^(?!/MisbehavingDir/.*$) to make ISAPI rewrite skip the next rule.

More Mod_rewrite problems

Ok, have a client that has existing links coming in from searchmarketing. I am in process of migrating the program from Cold Fusion to PHP.
RewriteEngine on
RewriteRule ^cat_ap~([^~]+)~(.*)\.htm$ /urban/cat_ap.php?$1=$2 [R]
Currently I have a URL structure:
http://www.test.com/urban/cat_ap~nid~5964.htm
which the above rewrite rule changes to
http://www.test.com/urban/cat_ap.php?nid=5964
Now I want to be able to get the variables out of the query string but maintain the url in the browser to the original http://www.test.com/urban/cat_ap~nid~5964.htm but still have it go to the PHP page.
So that when someone goes to http://www.test.com/urban/cat_ap~nid~5964.htm it actually goes to http://www.test.com/urban/cat_ap.php?nid=5964 but still shows http://www.test.com/urban/cat_ap~nid~5964.htm.
Any ideas on how to do this?
Thanks
Mike
You are already doing this on this line (but change the R flag to L):
RewriteRule ^/urban/cat_ap~([^~]+)~(.*).htm$ /urban/cat_ap.php?$1=$2 [L]
The URL that the user hits will still show as the .htm version while the server processes it as the .php
The R flag explicitly induces an external redirect. So just remove the R flag.
I think you'll need to set up reverse proxying to achieve the desired behaviour, and use the P flag with your rewrite rules. I've used a site with this sort of configuration before, so can say that it works, but I'm afraid I've never configured it myself :-(
A good first step at least would be to install mod_proxy and get it loaded and running. The mod_rewrite cookbook page on the P flag has a small amount of detail on proxying RewriteRules, and links through to the ProxyPassReverse directive documentation at apache.org.

How can I test if IIRF works?

http://www.codeplex.com/IIRF/Thread/List.aspx
My webhost installed IIRF for me and I am convinced that they did not do it correctly. I've tried numerous examples including one that I know works with apache's mod_rewrite but I can't get anything to work with IIRF. Is there rule or configuration option that you guys have that you know of that will show whether or not the thing is working correctly?
Even something like rewrite all urls to anothersite.com will will help me right now. I hope you guys realize the reason I came for your help. I can figure out how to do the rewrite rules on my own but I don't know if the errors are because of me or the webhost. I have limited options as well since I am on a shared webhost.
The new version of IIRF, v1.2.16 R3, includes a StatusUrl directive that will give you a status page if you do an HTTP GET on it. It looks like this:
If you get that page, then IIRF is running.
This is tested and working with IIRF:
RedirectRule ^.*$ http://www.google.com/ [I,R=301]
It will match any URL and redirect to Google.

Resources