I need a rewrite rule to redirect the root URL for a subfolder to the root of the domain, but I want to allow URLs in the subfolder. In other words:
www.domain.com/subfolder redirect to www.domain.com
www.domain.com/subfolder/ redirect to www.domain.com
www.domain.com/subfolder/page1 this should NOT redirect
Thanks!
Try this:
<configuration>
<location path="domain.com/subfolder">
<system.webServer>
<httpRedirect enabled="true" destination="http://domain.com" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<location path="domain.com/subfolder/">
<system.webServer>
<httpRedirect enabled="true" destination="http://domain.com" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
Related
I have a website hosted in IIS 10
The .js and .css files are versioned using this pattern ?v=a.b.c (where a.b.c is changed with a new number every time is required) in order to invalidate the cache browser.
This is how the site starts :
user enters www.sitename.com (or "localhost" in my case)
the index.html file is loaded . This files loads a main.js?v=a.b.c file that loads/configures "require.js" . Every other file from this point forward is handled by require (also management of the versioning for the html/css/js)
The problem that I am facing is the following :
How to invalidate the cache browser for index.html ?
I tried to send a no-cache header for the index.html with the following web.config file in IIS that works if I write localhost/index.html in the browser URL...but it does not work if I write only localhost (in this case the old index.html from the cache is loaded)
<configuration>
<system.web>
<urlMappings enabled="true">
<add url="~/" mappedUrl="~/index.html" />
</urlMappings>
</system.web>
<location path="index.html">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
Can I receive some help ?
you can set the no-cache header by using iis URL rewrite rule:
<system.webServer>
<rewrite>
<outboundRules>
<rule name="RewriteCache-Control" preCondition="old url with 301" stopProcessing="true">
<match serverVariable="RESPONSE_Cache-Control" pattern="(.*)" />
<conditions>
</conditions>
<action type="Rewrite" value="no-cache" />
</rule>
<preConditions>
<preCondition name="old url with 301">
<add input="{URL}" pattern="index.html|^$" />
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>>
</preConditions>
</outboundRules>
</rewrite>
<tracing>
<traceFailedRequests>
<add path="*">
<traceAreas>
<add provider="WWW Server" areas="Rewrite" verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="100-900" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
another way:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="index.html">
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
</configuration>
so I uploaded my website in GoDaddy and I used a Windows Hosting (Plesk). My only problem is that since it isn't running Apache as far as I know, it won't read my .htaccess file, which has all of my mod_rewrite code to remove the index.php in the URL. So my question is how do I implement a mod_rewrite in Plesk?
You can rewrite .htaccess file to IIS's web.config and place it inside /httpdocs folder.
You can do it by guides like this or this online converter or if you have Windows Server you can convert .htaccess by this guide (or you can share your .htaccess and i'll try to convert it for you)
I've found this snippet maybe it can help you:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Index">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
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>
For browser caching, I want to set expiration time for only one of my .js file in web.config not the whole js folder. For that I tried using the below configuration with the help of How to configure static content cache per folder and extension in IIS7? but it doesn't work:
<configuration>
<location path="compiled.js">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
</system.webServer>
</location>
</configuration>
Then I tried to change the path in "location" attribute as shown below but this also doesn't work for me:
<configuration>
<location path="~/js/compiled.js">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
</system.webServer>
</location>
</configuration>
Can someone help me how do I set cache expiration time for only one .js file instead of whole folder via web.config?
For a single file we can set caching expiration time in web.config file as shown below:
<configuration>
<location path="js/compiled.js">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>
</system.webServer>
</location>
</configuration>
Also, we can specify the cache settings for different files/folders by using different <location> sections.
I have a file (called 'log.html') on my iis7.5 server that I would like my PHP installation to be able to access and write to, but I do not want anybody to access the file directly, for example typing in 'http://computername/log.html' (I am on a LAN).
How can I prevent users from accessing it but allow php to see it?
When using the web.config file suggested below, I get this error:
You can use IIS URL Rewrite and create a Request Blocking Rule to prevent access over HTTP:
For example:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="BlockLogFile"
patternSyntax="Wildcard"
stopProcessing="true">
<match url="*" />
<conditions>
<add input="{URL}" pattern="/log.html" />
</conditions>
<action type="CustomResponse"
statusCode="403"
statusReason="Forbidden: Access is denied."
statusDescription="This is sekret!" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I think that I may have answered my own question! I still need to test it a bit more, and perhaps if it does not work completely then someone could correct me:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="cache-control" value="no-store, no-cache, must-revalidate, max-age=0" />
</customHeaders>
</httpProtocol>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
<security>
<requestFiltering>
<denyUrlSequences>
<add sequence="log.html" />
</denyUrlSequences>
</requestFiltering>
</security>
</system.webServer>
</configuration>
The cache control bit prevents the browser from caching anything that it returned.
Hope this helps somebody else! I am still very new to this, so you might be able to get around this.