IIS URL Rewrite pattern from subdirectory to subdomain with custom path extraction - iis

Previously there was this...
http://www.website.com/blog/post/2013/04/16/Animal-Kingdom's-Wild-Africa-Trek.aspx
(notice the apostrophe in 'Kingdom's')
and its now located at:
http://blog.website.com/post/Animal-Kingdoms-Wild-Africa-Trek
so, breaking it down the parts are...
remove .aspx from the end of the URL
map the call from www. to blog. and remove the blog part of the path
remove the date from the URL
remove the apostrophe
I understand how to redirect the subdirectory to a subdomain, but im stuck extracting the other parts of the path correctly, and cleaning out the apostrophe too.
A complete solution would be a great help, thanks in advance.

There is no way to remove all ', because it can be more than one. You could try following regexp (it allows up to 4 apostrophes), but it is quite "danger":
/blog/post/\d+/\d+/\d+/(([^']*)'*([^']*)'*([^']*)'*([^']*)'*).aspx
And redirect URL will be:
http://blog.website.com/post/{R:2}{R:3}{R:4}{R:5}
Bellow screenshot of my IIS Rule:

Related

How to remove (not hide) a subdirectory from a URL using .htacesss

I have a series of URLs on my website:
http://www.example.com/sub1/sub2/content.html
But I would like to remove "sub1" completely - not hide it so it still attempts to access that directory. Finished result would be this URL:
http://www.example.com/sub2/content.html
Many similar posts on SE seem to demonstrate how to "hide" a URL from the user. I want to rewrite the URL so that it treats it as if it isn't even there.
Example of what I'm trying not to do: Hide Part of URL htaccess
NOTE: I do not want to actually delete files as suggested by the comment below. I'm trying to redirect the request to another directory.
This worked for me:
RewriteRule ^sub1/sub2/(.*)$ /sub2/$1 [R=302,NC,L]
Helpful page: http://coolestguidesontheplanet.com/redirecting-a-web-folder-directory-to-another-in-htaccess/

Redirecting using wildcard

First question in here, so be gentle with me:)
Much easier to explain with examples of the url.
This is one of the current url's
domainname.com/loc/window-repair/england/
We now need to lose the /loc/ part of the url so that it would now point to
www.domainname.com/window-repair/england/
The problem is that it isnt just one url, there are approxcimately 1000 urls pointing to various destinations in the UK all with the loc part in the url, and they all have sub directories.
eg
domainname.com/loc/window-repair/england/north-east/darlington
or
domainname.com/loc/window-repair/england/north-east/
or
domainname.com/loc/window-repair/scotland/
How can I put in a redirect so that the link still works but without the loc part.
Many Thanks
Try this in your htaccess file:
RedirectMatch 301 ^/([^/-]+)-([^/-]+)/(.*)/?$ /loc/$1-$2/$3

links includes coma and hash htaccess

I'm using links like that:
find.php?id=1&n=2#loc
I want to my links look like:
but i dont know how to change htaccess and when/where use # to link some place in the page #loc
htaccess:
RewriteRule ^(.*),(.*),(.*)$ $3.php?id=$2&n=$1 [L,NC,NS,NE]
Help lease
The #loc part of the URL is never sent to the server, so there's no way for you to match against it in your htaccess file. Anything starting from the # in the URL is called a fragment and it's used by the browser, the server doesn't know it's even there.

Need URL Rewrite to replace a string in a url

I am looking and looking and coming up with all different patterns, but no such luck. I require a rewrite rule to handle the a replacement of a string xyzlisting with xyz-listing. It may be anywhere in the url. Is there a straightforward way to write this rule?
I am not so experienced with IIS. However, I can suggest something:
In Apache mod_rewrite, you can use this rule:
RewriteRule (.*)(/\w+)(listing)(.*)$ $1$2-$3$4
This rule will split whatever string in the format anything followed by 'listing' that comes after mydomain.com/ with a '-'. Which results in 'anything-listing', wherever in the URL.
This will only change the last occurrence of this type of string. It will not replace more than one occurrence.
You can import this URl rewrite rule from Apache to IIS using this IIS extension:
IIS Extenson page for url rewrite module
Hope this helps :)

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.

Resources