Trying to exclude css and js files with IIRF rewrite - iis

I'm trying to get IIRF working so that it rewrites certain URLs, but ignores files like .css and .js files.
I have URLs like:
/admin/
/admin/user/
/admin/user/view-details/1
/admin/user/view-details/1?edit
Which all work, but I can't seem to get this to work:
/admin/_assets/css/admin.css
My .ini file looks like this:
RewriteRule /admin/([^/]+)/([^/]+)/([^/]+)\?edit$ /admin/index.php?edit&action=$1&sub-action=$2&id=$3 [L,I,QSA]
RewriteRule /admin/([^/]+)/([^/]+)/([^/]+)$ /admin/index.php?edit&action=$1&sub-action=$2&id=$3 [L,I,QSA]
RewriteRule /admin/([^/]+)/$ /admin/index.php?action=$1 [L,I,QSA]
RewriteRule ^/admin/(.*)$ - [L]
I've also tried:
RewriteRule (.+\.)(php|jpg|png|jpeg|gif|ttf|sql|txt|htm|zip|css)$ - [L]
The things I've tried give either a blank document when I navigate directly to the css file, or I get:
HTTP Error 404.4 - Not Found
The resource you are looking for does not have a handler associated with it.
I don't have much experience with IIRF or IIS, so I'm a bit stuck with what to try next. Am I looking in the wrong place? Or have I made a really basic mistake?
Thanks

Tip for debugging iirf: use StatusUrl to check first for problems.

I've managed to fix this by adding:
RewriteRule /admin/_assets/(.+)$ /admin/_assets/$1 [L,I,QSA]
to the top of my file. I'm still not sure why nothing is being logged, but this fixed it for my needs.

Related

Remove a directory with ISAPI RewriteRule

I'm trying to rewrite a web address to remove a directory, if it exists. In other words, if someone navigates to www.domain.com/a/bad/b/c/page.pdf, the RewriteRule should remove /bad/ and send them to www.domain.com/a/b/c/page.pdf.
The /bad/ directory will always be in the 2nd position in the URL, as in the example. The paths will always be to PDFs, if that makes a difference.
I've tried things, but no luck. I feel like this should be fairly simple. Any suggestions?
OK, after more digging I found my answer:
RewriteRule ^a/bad/(.*)$ /a/$1

rewriteRule for URL path not working correctly

I need help with a URL problem I've encountered with a rewriteRule.
What I need it to do is following: example.com/en/page/page/
At the moment the following works fine: example.com/en/page/
But once it goes like "example.com/en/page/page/" I receive a 404 - page not found error even if the page in fact is located in the serverfiles.
The clue here is that I use a variable in the /en/ part of the URL (multilanguage system) and it seems that I cannot figure out how to get it to work with that included.
At the moment I have the following rewriteRule in my .htaccess file.
RewriteRule ^([^/]*)/([^/]*)/?$ index.php?lang=$1&uri=$2 [L]
Do any of you have a clue on what might work?
Best regards,
PureDarkness
You don't include anything behind the second /. You could try:
RewriteRule ^([^/]*)/(.*)$ index.php?lang=$1&uri=$2 [L]
And you can add [QSA] if you also need to get the parameters.

Use htaccess to mask folder name

Here's a problem I'm always wanting to solve with htaccess. I haven't found a way yet, though it looks like it should be possible - perhaps someone can help.
Let's say I have a folder at the root of my site called /foo/. I want users to be able to access that folder at the path /bar/, but for various reasons I can't rename the folder.
So as not to create confusion I only want one path to ever be seen - that is to say, I don't want people to use the name /foo/ to access the folder; they should always use /bar/. If someone goes to example.com/foo/, their browser should redirect to example.com/bar/ - but the content returned should be the content of /foo/.
To make matters more complicated, pages in /foo/ have dependencies (images, stylesheets, links to other pages, etc) within /foo/ which are hardcoded and can't be changed. These must, of course, still work.
So, to summarise, this is what I want :
Requests for example.com/foo/ should redirect to example.com/bar/.
Requests for example.com/bar/ should return the contents of example.com/foo/.
Is this possible? It looks on the surface as if it would create an infinite redirect... but I'm pretty sure there are ways to prevent that in htaccess, aren't there?
I'd be very grateful for any help.
(PS - for a little extra background: The normal reason I want to do this is to rename the wordpress /wp-admin/ directory to something more professional and easy for customers to remember, such as /admin/. But the same system should work for masking any path in this way.)
I found a sort of workaround - by using a symlink and htaccess in combination.
First I created a symlink from /bar to /foo/.
Then I put this in htaccess :
Options +FollowSymLinks
RewriteRule ^foo/(.*)$ bar/$1 [R,L]
This has exactly the desired result - example.com/bar/ shows the content of the /foo/ directory, and example.com/foo/ redirects to example.com/bar/
But if anyone can come up with a pure htaccess solution I'd much prefer that!
Update :
Ok, I've finally found out how to do this. It turns out to be quite simple...
RewriteCond %{THE_REQUEST} ^GET\ /foo/
RewriteRule ^foo/(.*)$ bar/$1 [R,L]
RewriteRule ^bar/(.*)$ foo/$1
The only problem is that it doesn't take account of RewriteBase, so you have to include the full path in the first line (after ^GET\).
If I understand correctly what you want is something like this inside your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^foo/$ bar/
RewriteRule ^bar/$ foo/
</IfModule>

.htaccess RewriteRule help

I have been able to change the 'location' of my images with RewriteRule, but I have 3 lines of code to do this because of subdirectories in the image folders
RewriteRule ^images/([^/]+).(jpg|jpeg|bmp|gif|png)$ /includes/images/$1.$2
RewriteRule ^images/([^/]+)/([^/]+).(jpg|jpeg|bmp|gif|png)$ /includes/images/$1/$2.$3
RewriteRule ^images/([^/]+)/([^/]+)/([^/]+).(jpg|jpeg|bmp|gif|png)$ /includes/images/$1/$2/$3.$4
However, I would like to be able to not need to add to these if I ever add any deeper subdirectories.
I have tried many different approaches to this with no luck, and the following is what I am stuck with atm.
RewriteRule ^(images)(/?[^/])+(.jpg|.jpeg|.bmp|.gif|.png)$ /includes/$&
Does anyone have any ideas on how to get this code to work??
Also, is there any way to view the URL that is being used server-side?
Perhaps I'm missing something, but I don't see any reason that you couldn't simply do:
RewriteRule ^images/(.+)\.(jpg|jpeg|bmp|gif|png)$ /includes/images/$1.$2

Rewrite rules for subfolders

This may seem like a silly question but I can't figure it out.
let's say I have a public_html folder with various folders like: Albatross, Blackbirds, Crows and Faqs.
I want to make it so that any traffic to Albatross/faqs.php, Blackbirds/faqs.php, Crows/faqs.php etc will see the file that is at faqs/faqs.php?bird=albatross or faqs/faqs.php?bird=crows or what have you.
If I go into the Albatross folder's .htaccess file I can do this
RewriteRule faqs.php$ /faqs/faqs.php?cat=albatross[QSA]
Which works fine, but I want to put something in the top level .htacces that works for all of them, so tried:
RewriteRule faqs.php$ /faqs/faqs.php?cat=albatross[QSA]
RewriteRule /(.*)/faqs.php$ /faqs/faqs.php?cat=$1 [QSA]
and even
RewriteRule /albatross/faqs.php$ /faqs/faqs.php?cat=albatross [QSA]
and various others but nothing seems to work, when I go to http://www.birdsandwhatnot.com/albatross/faqs.php I see the same file the same way it's always been. Does the presence of an .htaccess file in the subfolder conflict with the higher up .htaccess file?
Am I missing something?
A small correction should do the trick
RewriteEngine on
RewriteRule ^(.*)/faqs.php$ /faqs/faqs.php?cat=$1 [QSA]
"/" is not being passed to parser.
Hope it helps

Resources