I am using apache mod rewrite and i have a .htaccess rewrite statement. I would like to change over to use IIS server and would like to know if any one can give me advice on how to convert my existing .htaccess statement to iis web.config.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
Expert Advice appreciated.
For IIS 7 you would use <system.webServer><rewrite> section. There is an excellent article on translating .htaccess to web.config here
<rewrite>
<rules>
<rule name="Your Rule" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" />
</rule>
</rules>
</rewrite>
Resolved. Download url rewrite from Microsoft web platform installer. Url rewrite module can auto create the web.config when you specify the rules via their ui.
Related
I would like to take the following URL
http://MYSERVER/API_Tasks/V1/controller/task.php?taskid=2
and rewrite it to:
http://MYSERVER/API_Tasks/V1/tasks/2
I have the following rule created but it does not seem to work
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^tasks/([0-9]+)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="controller/task.php?taskid={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
original Apache .htaccess rules
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^tasks/([0-9]+)$ controller/task.php?taskid=$1 [L]
The issue was actually caused by the rule in IIS being placed on the API_Tasks directory and not the API_Tasks/V1 directory. Adding the URL rule to the V1 fixed the issue.
I have main domain and I want to rewrite images form another one to main without redirect
Here is my code:
RewriteCond %{HTTP_HOST} ^www.mydomain\.eu$ [NC]
RewriteRule ^images/(.*)$ https://www.mydomain.cz/images/$1 [NC]
It always does 302 redirect.
Is there any way how to do this? I am using ISAPI_Rewrite, but I tried IIS 10 rewrite too, but I am not familiar with that and I wasnt successful at all
Thanks
According to your description, I suggest you could try to below use url rewrite rule in the IIS.
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^images/(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www.mydomain\.eu$" />
</conditions>
<action type="Rewrite" url="https://www.mydomain.cz/images/{R:1}" />
</rule>
I made a directory in my host:
www.mysite.com/test/
and I've copied my laravel folders inside it. but when I call that url on my browser it show me this:
I think I should make a .htaccess .
Here is sample for my case and your case:-
My Case:-
URL Before .htaccess www.xyz.com/public/index.php
URL After .htaccess www.xyz.com
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* public/index.php [L]
Your Case:-
URL Before .htaccess www.xyz.com/test/public/index.php
URL After .htaccess www.xyz.com
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* test/public/index.php [L]
The Laravel app is inside /public folder, which also already has a .htaccess: mysite.com/public/test
What you can do is symlink the project/public folder to the public directory. For example:
ln -s /path/to/project/public /var/www
Now you should be able to see the app on mysite.com/test.
This article on deploying a Laravel 5 application might help.
The
.htaccess
file is already existed in public folder what you need to configure is your server
for Linux on terminal execute :
cd /etc/apache2/sites-available
/etc/apache2/sites-available$ sudo vi myapp.conf
Add/Modify these lines to suit your server
<VirtualHost *:80>
ServerName myapp.localhost.com
DocumentRoot "/home/vagrant/projects/myapp/public"
<Directory "/home/vagrant/projects/myapp/public">
AllowOverride all
</Directory>
</VirtualHost>
Save the file, then continue below.
/etc/apache2/sites-available$ cd ../sites-enabled
/etc/apache2/sites-enabled$ sudo ln -s ../sites-available/myapp.conf
/etc/apache2/sites-enabled$ sudo service apache2 restart
And for Windows Servers inside your Laravel root folder add web.config file and write these codes inside it
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="default.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
</files>
</defaultDocument>
<handlers accessPolicy="Read, Execute, Script" />
<rewrite>
<rules>
<rule name="Imported Rule 1">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="/public/{R:1}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="public/index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
)
Create an .htaccess file on your laravel's root directory. This is to access it without the "public" on the url
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI}!^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
My previous web server ran apache with rewrites in each site's .conf file. I wouldn't even consider myself an intermediate rewrite user so this may not be ideal. I'm trying to reproduce this:
# except for requests for URL-path /abc/abc_system<whatever>
RewriteCond %{REQUEST_URI} !^(/abc/abc_system|/abc/themes|/abc/admin.php)
RewriteCond %{HTTP_HOST} ^([^.]+\.)*abctest\.example\.com [NC]
RewriteRule ^/abc/(.*)$ /abc/index.php/abc/$1 [L]
# one
RewriteRule ^/one/(.*)$ /one/index.php/one/$1 [L]
# two
RewriteRule ^/two/(.*)$ /two/index.php/two/$1 [L]
# three
RewriteRule ^/three/(.*)$ /three/index.php/three/$1 [L]
within IIS 8 using URL Rewrite.
<rewrite>
<rules>
<clear />
<rule name="abc ee" stopProcessing="false">
<match url="^abc/(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="^(/abc/abc_system|/abc/themes|/abc/admin.php)" ignoreCase="false" negate="true" />
<add input="{HTTP_HOST}" pattern="^([^.]+\.)*abctest\.example\.com" />
</conditions>
<action type="Rewrite" url="/abc/index.php/abc/{R:1}" logRewrittenUrl="true" />
</rule>
<rule name="abc one" stopProcessing="false">
<match url="^/one/(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
</conditions>
<action type="Rewrite" url="/one/index.php/one/{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
The first rule is working but the second one ("abc one") isn't, so I haven't even bothered adding the rules for "two" and "three" yet.
Basically the urls look something like this:
example.com/abc -> example.com/abc/index.php/abc (working)
example.com/one -> example.com/one/index.php/one
example.com/two -> example.com/two/index.php/two
example.com/three -> example.com/three/index.php/three
What am I doing wrong that the second rule isn't working?
Once that's fixed, is repeating it the best way to go about it or is there a more efficient way to condense them down?
Many thanks!
you can use "OR" to catch the two/three cases and will be faster, I tested the following rule and it worked fine:
<rule name="RewriteOneTwoThree" stopProcessing="true">
<match url="^(one|two|three)/(.*)$" ignoreCase="false" />
<action type="Rewrite" url="/{R:1}/index.php/{R:1}/{R:2}" />
</rule>
I have searched all over this site and the web and still I cannot get this right. I have many URLs like this: http://archives.cancunandrivieramaya.com/archives/cancun.cgi/md/read/id/XXXX that I want to redirect to the home page http://www.cancunandrivieramaya.com/. The subdomain no longer exists. How do I write the mod-rewrite to redirect the subdomain with wildcard characters at the end to the homepage? This is one of the 100's that don't work :(
RewriteCond %{HTTP_HOST} !^www\.cancunandrivieramaya\.com [NC]
RewriteCond %{HTTP_HOST} ^archives\.cancunandrivieramaya\.com([a-z0-9]+)\
RewriteRule (.*) http://www.cancunandrivieramaya.com/[L,QSA]
Any help would be much appreciated.
I got it! Thanks to this article by Altaf Khatri http://www.altafkhatri.com/Technical/Configure/How-to-publish-or-host-subdomain-on-winhostcom/Solution-resolution I was able to follow his step-by-step instructions for setting up the subdomain on WinHost, then I added this rule to the web.config file:
<rule name="archive redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.archives\.cancunandrivieramaya\.com$" />
</conditions>
<action type="Redirect" url="http://www.cancunandrivieramaya.com/" />
</rule>
<rule name="archives 2" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?archives\.cancunandrivieramaya\.com$" />
<add input="{PATH_INFO}" pattern="^/archives/($|/)" negate="true" />
</conditions>
<action type="Redirect" url="http://www.cancunandrivieramaya.com/" />
</rule>
Works perfectly!