htaccess not working in iis - .htaccess

friends. I'm creating an .htaccess file with rewrite rules. It's working fine in localhost, but on the live, server it's not working. My hosting uses a Window server.
I wrote this Rule in my .htaccess file:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

By default, IIS does not support .httacces and Apache mode_rewrite rules. To achieve this, you will have to install Helicon Ape addon along with IIS. Helicon Ape offers support for the Apache .htaccess and .htpasswd configuration files in Microsoft IIS.
With Helicon Ape you can use modules, like mod_rewrite, mod_proxy, mod_auth, mod_gzip, mod_headers, mod_cache, mod_expires, mod_replace and others under single IIS addon. Single website license for Helicon Ape will cost you $47 one time.
If you want to have free alternative, you can go with native IIS URL Rewrite Module. Microsoft URL Rewrite module offers similar functionality like Apache mod_rewrite module with the help of web.config file. You can simply install this module and import your .httacces rules to IIS web server. This module also lets you convert the existing Apache mod_rewrite rules to IIS URL rewrite rules and store them to web.config automatically. For more information, refer to following tutorial.
https://manage.accuwebhosting.com/knowledgebase/2415/How-to-Enable-modrewrite-on-IIS-Web-Server.html

Related

Rewrite web server apache for IIS

I need to translate htaccess rewrite rule for a IIS web server, can you help me with the sintax? for example:
RewriteCond %{QUERY_STRING} ^orderby=([0-9]+)&pagesize=([0-9]+)&pagenumber([0-9]+)$
RewriteRule ^[OLD-SLUG]$ https://www.[DOMAIN].it/[NEW-SLUG]? [R=301,L]
Or:
RewriteRule ^[OLD-SLUG]$ - [G]
Thanks
Many PHP applications currently ship with rewrite rules as part of their .htaccess file. These rules tell Apache's mod_rewrite how and when to rewrite incoming requests. The IIS URL Rewrite module can read these rules and translate them into URL Rewrite rules.
For more information about importing Apache mod_rewrite rules, see: Importing Apache mod_rewrite Rules.

htaccess URL masking subfolder to another domain instead of redirecting

I need to redirect www.domain.com/folder to subdomain.anotherdomain.com without change the first url, www.domain.com/folder. In www.domain.com I have a WordPress site and in subdomain.anotherdomain.com a Moodle site. By that, only www.domain.com/folder must have a redirect, not the www.domain.com or www.domain.com/other_folder. It can be done? It´s possible?.
In the Worpress site I´ve this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I try with a iframe, but a Google Chrome don´t like that :/ (cookies issues)
Many thanks in advance.
You cannot somehow keep a URL pointing to one http server visible in the browsers URL bar but make it connect to some other http server. That would be a gigantic security issue.
If you can change the setup such that both host names point to the same http server, then what you ask can be achieved by applying simple some internal rewriting rules.
For separate http servers your only option is to use the proxy module the apache http server brings, if it is installed and enabled ...
ProxyPass /folder https://subdomain.anotherdomain.com
ProxyPassReverse /folder https://subdomain.anotherdomain.com
See the documentation of the proxy module for details: http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypass
The proxy module can also be used from within the rewriting module, but this comes with an optional decrease of speed:
RewriteEngine on
RewriteRule ^/?folder/(.*)$ https://subdomain.anotherdomain.com/$1 [P,QSA,END]
Again this is documented in the rewriting module:
http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p

send all .xml requests to proxy

I have an Angular application that pulls in content from a CMS for articles via an API. I want to utilize the XML sitemap generated by the CMS. The CMS is hosted at content.example.com and the Angular site is the www. What I would like to do is catch all .xml requests and load the content site by proxy. What I have in my .htaccess is:
RewriteCond %{REQUEST_FILENAME}
RewriteRule ^\.*?\.xml$ https://content.example.com/$2 [P,L]
However, that is not working. Fairly new to mod rewrite so I am assuming my logic is off. Not finding a lot of examples of this. Any help would be appreciated.
You could write your rule this way
# Only apply next rule when domain is www
RewriteCond %{HTTP_HOST} ^www\. [NC]
# (Proxy) rewrite all xml files to its proxy equivalent
RewriteRule ^(.+)\.xml$ https://content.example.com/$1.xml [P]

Symfony .htaccess

I configured a test folder for websites in hostgator, so far I have no problems in some flatform like wordpress,magento,joomla, I did not even change any seetings in .htaccess to make it run. Recently, I am working on a symfony2 project and upload my test application in the test folder I created. This is how I create a test folder
mywebsite.com/tests/wordpress_site(no problem)
mywebsite.com/tests/joomla_site(no problem)
mywebsite.com/tests/symfony2_site(403 forbidden error)
In my WAMP, I can accessed my symfony project
localhost/symfony_site/web/
I did not touch the .htaccess since this is just a test site in local machine.
How would you configure a symfony2 project in this setup?
mywebsite.com/tests/symfony_site
It is almost impossible to create clean Urls when installing symfony in subfolder...
With Apache, the better solution is to use a VirtualHost which have tests/symfony_site/web as DocumentRoot, and to use the built-in .htaccess file (which uses url rewriting module, or if it not available, uses a 302 redirection to app.php/)
But If you can't add a virtualHost to your server, it is hard...
An other way is to add a .htaccess at tests/symfony_site and put DirectoryIndex: web/app.php
(https://httpd.apache.org/docs/current/mod/mod_dir.html)
So you can have clean URLs... but be careful with this solution: the urls parsed by the router are relative to your site root (and not to symfony root...) so the router might be lost... (e.g if you have a root named /test you should rename it /tests/symfony_site/test... And it is the same for assets, you have to add the site directory, otherwise they will return a 404 error...
In my case, I just use existing .htaccess in web folder (or I create a new one with a DirectoryIndex Instead), so my app work with URLs like mywebsite.com/tests/symfony_site/web/
I hope this helped,
Vincent
You can try typing the following code into the .htaccess file to the symfony root folder
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(img|files|images|favicon.ico|css|js|robots\.txt)
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{HTTP_HOST} host.com
RewriteCond %{REQUEST_URI} !web/
RewriteRule ^(.*)$ web/$1 [L]

ISAPI_Rewrite 3.0 ... Noob ... how to get started? just installed

just installed v3 lite to try it out before getting full version.
i got the follwing in .htaccess file in the root folder of the .net web app
RewriteEngine On
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP_HOST} ^zzzz-wildcard\.domain\.com
RewriteRule ^(.*)$ http://domain.com/zzzz-wildcard$1 [R]
problem is it doesn't do anything. i got the wildcard set up on iis so that
test.domain.com is served just as domain.com would be.
What i want to achieve is to serve any sub-domain user1.domain.com as domain.com/zzzz-wildcard
from what i got so far even explicity supplying zzzz-wildcard.domain.com still serves the default.aspx of the domain.com instead of domain.com/zzzz-wildcard/default.aspx
please help. i have never worked with isapi rewrite so i have no clue how to go about this.... right now as it stand it doesn't really do anything. can't say i'm good with regular expressions either :(
When opening ISAPI_Rewrite Manager and selecting my domain.com from the list of iis websites it says No properties available for this node.
******** EDIT ********
after some more looking around i found out that lite version doesn't support .htaccess so only httpd.conf file that works globally. So anyway i modified the httpd.conf file instead and it now works..
however it just redirects zzzz-wildcard.domain.com to domain.com/zzzz-wildcard
Is there a way to keep the url intact and not redirect? but still serve the pages from domain.com/zzzz-wildcard ?
finally solved after looking around other answers on stackoverflow
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*?)\.domain\.com$ [NC]
RewriteRule (.*) /zzzz-wildcard/%{REQUEST_URI} [NC]

Resources