Why isn't my IIS Rewrite rule working for images? - iis

I have some code that points to this URL that doesn't exist:
http://www.newradicals.com/movies/(500) Days of Summer (2009)/folder.jpg
I want it to rewrite to this URL:
http://www.newradicals.com/movies/(500) Days of Summer (2009)-poster.jpg
I have the following rule set up but it's not working at all. When I go to the image URL in the browser, nothing happens, I still get a 404.
Match URL (matches pattern, regular expression):
^([^]+)/movies/([^]+)/folder.jpg
Rewrite to:
movies/{R:2}-poster.jpg
Anyone know why this isn't working and what I need to do to fix it?

Answering my own question...
I found that I needed to just change the pattern to remove the domain:
^movies/([^]+)/folder.jpg
and then slightly modify the rewrite:
movies/{R:1}-poster.jpg

Related

.htaccess rewrite url that has already been changed

I am upgrading my site which involves new scripts and a different URL
structure. There are currently a few thousand pages so I want to
basically move them in to a subdirectory so that they are not lost.
I am not very confident with htaccess so can someone please confirm that
the first part I have done is correct:
Old URL: http://www.example.com/article/another-dir/page-group/whatever.html
RewriteRule ^article/?$ http://www.example.com/archive/ [R=301,NC,L]
To achieve this: http://www.example.com/archive/another-dir/page-group/whatever.html
Search engines will see the above as a permanent move and in the address bar
it will show the new url. Is this right?
The second part is on the new script - the url's could be improved but I am
unable to change all the script so thought about using htaccess again but am
not sure if it can be achieved like this.
At the moment the url looks like this:
url: http://www.example.com/category/4/categoryname
In the htaccess the current rewrite rule for this type of url looks like this:
RewriteRule ^category/(.*)/(.*)$ category.php?id=$1&slug=$2
Is it possible to change this so that in the url address bar I end up
with this:
http://www.example.com/categoryname
Basically I don't want to see either the number or category/ in the resulting
url as it will be easier for visitors to use - is that possible??
Thanks in advance for any help.
The second question related to passing in URI components for querystring redirect and then hiding those components in the URL I don't think would be easy, if even possible, using RewriteRules.
For the first question though. Given the sample URLs you mentioned, the RewriteRule would need to include capture and backreference if you want to preserve the full URL in the redirection. For example:
RewriteRule ^article/?(.*)$ http://www.example.com/archive/$1 [R=301,NC,L]

htaccess rewrite URL with Google tracking code

First of all, sorry for my english... I hope you're going to understand my problem :)
My company has made an emailing campaign which included a link to our website. This URL has a Google tracking code to follow the campaign.
Unfortunately, the URL is wrong :
http://www.mysite.fr/category/mypage.html/?utm_source=source&utm_medium=medium&utm_campaign=campaign
but there's a slash between "mypage.html" and the tracking code which points to an inexistant page.
I tried these rules to redirect the url without sending a new email to everyone but they don't work :
RewriteRule ^/category/mypage\.html/\?utm_source\=source\&utm_medium\=medium\&utm_capaign\=campaign$ http://www.mysite.fr/category/mypage.html?utm_source=source&utm_medium=medium&utm_campaign=campaign [R=301,L]
Or :
RedirectPermanent /category/mypage.html/ http://www.mysite.fr/category/mypage.html?utm_source=source&utm_medium=medium&utm_campaign=campaign
I don't know how to write the rule. Can someone help me please ?
A few things are wrong with your RewriteRule. If you're putting this in an .htaccess file, you need to remove the leading slash (the prefix) in your regular expression because apache removes it from the URI before putting it through rules in .htaccess files. Second, you can't match against the query string (the stuff starting from the ?) in the regular expression in a RewriteRule.
Not sure why your RedirectPermanent isn't working. That looks fine other than the fact that the query strings automatically get appended if you leave them out. I think that's what you want, so remove the query string in the target:
RedirectMatch 301 ^/category/mypage.html/$ http://www.mysite.fr/category/mypage.html

Magento category urls infinite redirect

In Magento, I currently have on the site category urls which have no trailing slash, i.e. www.example.com/gifts
I want to change category urls to have a trailing slash, such as www.example.com/gifts/
To do this I went into the admin section, and edited the SEO section under system -> Configuration -> 'Catalog' -> Search engine optimizations.
There I added a '/' in the Category URL Suffix box.
That is all standard, and after rebuilding the index, the site does indeed display all category urls with a trailing slash, e.g. www.example.com/gifts/
The problem is, when I click on www.example.com/gifts/ (or any category now), I get an infinite redirect loop.
Chrome says "Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.", and doing a CURL -I -0 on the url shows a 301 redirect to Location: /gifts/.
I have checked my htaccess file, and there are definitely no rules related to trailing slash or category redirects.
EDIT: I have logging enabled on htaccess too, and I keep getting lines like:
strip per-dir prefix: /var/www/blah/app-core/index.php -> index.php
Is that normal?
Has anyone seen this issue before, or have any idea at all what might be causing this?
Its a complete blocker for me, so any insight or help would be very appreciated.
Thanks
Paul
Ha ha!!! Sorry, going a bit mad here!
Finally figured it out - I think it might be a bug in Magento 1.4.
In the Mage/Core/Model/Url/Rewrite.php file, request path is given as:
$requestPath = trim($request->getPathInfo(), '/');
So my request of '/gifts/' becomes 'gifts'. Magento then tries to append a slash, and it cycles over ad infinitum.
When you change the trim() to an ltrim(), it works. I.e.
$requestPath = ltrim($request->getPathInfo(), '/');
Now '/gifts/' is 'gifts/', and www.example.com/gifts/ is a 200!
Of course its a pain now to have to extend Magento just for such a minor tweak...
It sounds like your url rewrite table needs to be rebuilt. Login to your admin area and reindex the url rewrites.

htaccess redirects that ignore query string

I've recently inherited a webserver whose IP previously belonged to a well known band's forums.
Problem is I'm now drowning in 404 errors!
The URLs in question look like this:
http://[server_ip]/forum/ucp.php?mode=register&coppa=0
http://[server_ip]/forum/viewtopic.php?f=3&t=45330
http://[server_ip]/forum/index.php+++++++++++++++++++++++++++++++++++++++++++++++Result:+%ED%E5+%...
http://[server_ip]/forum/viewtopic.php?f=3&t=44597&start=0
In an ideal world I would like to redirect any traffic going to /forum/ucp.php, /forum/viewtopic.php or /forum/index.php elsewhere regardless of query string.
Or anything going to /forum/.* elsewhere, if that's doable.
I've tried a number of different solutions with little success, any help appreciated.
Assuming that you want to redirect all traffic to /forum/.* to http://mysite.com/somedirectory, which you can replace with the actual URL you wish to redirect to, you can add the following to the .htaccess in the root directory of your sites domain.
RewriteEngine On
RewriteBase /
#for any request starting with forum
RewriteRule ^forum/ http://mysite.com/somedirectory? [NC,L,R=302]
Be sure to keep the ? if you want to remove the query string params from the original query. If you want to make it a permanent redirect, change the 302 to a 301.
Don't really know what you have tried so far but this site will probably help you.
http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/#redirects

.htaccess url masking

I have a couple of wordpress urls that I want to simplify for SEO purposes. I have
http://www.example.com/fr/product-fr/review-fr/
I would like to change that to http://www.example.com/fr/product/review/ (remove -fr) but without changing the URL internally. So the user would access http://www.example.com/fr/product/review/ but the server would serve the content of http://www.example.com/fr/product-fr/review-fr/.
I want to do this to get around a URL problem with Wordpress and WPML.
Appreciate the help
Assuming the two letter lang code is always going to be constant throughout the URL:
RewriteEngine on
RewriteRule ^([A-Za-z]{2})/product/review$ /$1/product-$1/review-$1 [L,QSA]
should work a treat :)
P.S. the regexp takes any two-letter code (upper or lower case) so will work with other langs should you require.
Have you tried mod_rewrite and Rewrite rules?
Try:
^/([a-zA-Z]{2})/([^\/]+)/([^\/]+)/$ /$1/$2-$1/$3-$1
Haven't tested this though..

Resources