I have an site in IIS, lets say www.example.com (Laravel application) , and i have my subdirectory www.example.com/subdirectory (Django application), when i access the /subdirectory, the domain overwrite my subdirectory and I get 404 page of Laravel,
I tried to make an rule in web.config of domain but i didn't get results, and I don't know what to
So, this is my configs in main.settings( Django)
USE_X_FORWARDED_HOST = True
FORCE_SCRIPT_NAME = '/subdirectory/'
SESSION_COOKIE_PATH = '/subdirectory/'
LOGIN_REDIRECT_URL='/subdirectory/'
LOGOUT_REDIRECT_URL='/subdirectory/'
VIRTUAL_DIRECTORY = "subdirectory/"
ALLOWED_HOSTS = ['example.com', 'localhost', 'wwww.example.com']
and my urlpatterns in main.urls
urlpatterns = [
path(f'{settings.VIRTUAL_DIRECTORY}admin/', admin.site.urls),
# path('password_change/', views.password_change, name='password_change'),
path(f'{settings.VIRTUAL_DIRECTORY}', include('django.contrib.auth.urls')),
path(f'{settings.VIRTUAL_DIRECTORY}', views.index, name='index'),
path(f'{settings.VIRTUAL_DIRECTORY}aluno/', include('aluno.urls')),
path(f'{settings.VIRTUAL_DIRECTORY}empresa/', include('empresa.urls')),
]
and the web.config on Laravel
<configuration>
<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="image/*" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1048576000" />
</requestFiltering>
</security>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="Default.htm" />
<add value="default.aspx" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
</files>
</defaultDocument>
<rewrite>
<rules>
<clear />
<!-- INICIO - TO WWW -->
<rule name="Redirect to www" enabled="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" />
</rule>
<!-- FIM - TO WWW -->
<!-- INICIO - HTTP to HTTPS -->
<rule name="HTTP to HTTPS" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
<!-- FIM - HTTP to HTTPS -->
<!-- FIM - LINKS REDIRECIONAMENTOS -->
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" url="/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<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="index.php" />
</rule>
<rule name="subdirectory" stopProcessing="true">
<match url="^subdirectory(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
</conditions>
<action type="None" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
<handlers>
<remove name="PHP53_via_FastCGI" />
</handlers>
<staticContent>
<mimeMap fileExtension=".apk" mimeType="application/vnd.android.package-archive" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>
<caching enabled="true" enableKernelCache="true" />
</system.webServer>
<system.web>
<httpRuntime maxRequestLength="1048576" />
<customErrors mode="Off" />
</system.web>
</configuration>
Related
with some hit and trail, i managed to remove the extention of the pages which i view for my website, now i want to replace all the ? and = and the & signs with backslash /, I am really Lost now, how do i write that rule in my web config
My Web.Config File:
<rewrite>
<rules>
<rule name="Redirect .cfm extension" stopProcessing="false">
<match url="^(.*).cfm$" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="(.*).cfm$" ignoreCase="false" />
</conditions>
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="hide .cfm extension" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}.cfm" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:0}.cfm" />
</rule>
</rules>
</rewrite>
with the above, i managed to get a page like this
http://website.ca/graphics?mode=Graphics%20Design%20%C2%BB%20Business%20cards&catID=35§ion=graphics
the graphics? is the one which was before graphics.cfm?
I am having some trouble setting up my website on Azure. My website is developed using Django and I am using wfastcgi to run it on the server; but the server keeps giving an error that says, "scriptProcessor could not be found in application configuration." Here is the error exactly:
Here is my web.config file:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
<add key="PYTHONPATH" value="D:\home\Python27" />
<add key="DJANGO_SETTINGS_MODULE" value="iasf.settings" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="Python27_via_FastCGI" />
<remove name="Python34_via_FastCGI" />
<add name="Python FastCGI"
path="handler.fcgi"
verb="*"
modules="FastCgiModule"
scriptProcessor="D:\home\Python27\python.exe|D:\home\Python27\Lib\site-packages\wfastcgi.py"
resourceType="Unspecified"
requireAccess="Script" />
</handlers>
<rewrite>
<rules>
<rule name="Static Files" stopProcessing="true">
<conditions>
<add input="true" pattern="false" />
</conditions>
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite"
url="handler.fcgi/{R:1}"
appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I've installed wordpress in Azurewebsites which is primarily running Django. I've set up an application as /blog to /site/wwwroot/blog in application setting.
But web.config is not serving the url www.example.com/blog instead it's throwing 404 error.
Here's the web.config, could you suggest how to disable rewrite for www.example.com/blog
<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<appSettings>
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\site\wwwroot\env\Scripts\python.exe" />
<add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_venv_handler()" />
<add key="PYTHONPATH" value="D:\home\site\wwwroot" />
<!--
<add key="WSGI_PTVSD_SECRET" value="" />
-->
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<!-- Required for websockets. -->
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="Python340_via_FastCGI" />
<add name="Python FastCGI" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\Python34\python.exe|D:\Python34\Scripts\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
<!-- Uncomment the following handler to enable remote debugging. -->
<!--
<add name="ptvsd" path="ptvsd" verb="*" resourceType="Unspecified" type="Microsoft.PythonTools.Debugger.WebSocketProxy, Microsoft.PythonTools.WebRole"/>
-->
<!-- <clear/>
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
-->
</handlers>
<rewrite>
<rules>
<!-- Uncomment the following rule to enable remote debugging. -->
<!--
<rule name="ptvsd" enabled="true" stopProcessing="true">
<match url="^ptvsd(/.*)?$"/>
</rule>
-->
<rule name="Static Files" stopProcessing="true">
<conditions>
<add input="true" pattern="false" />
</conditions>
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<staticContent>
<clientCache cacheControlMaxAge ="7.00:00:00" cacheControlMode="UseMaxAge" />
</staticContent>
</system.webServer>
</configuration>
According to your description, I suggest you could try to add a not match condition in the rules.
If the url's target is blob folder, then it will not be rewrite.
More details, you could refer to below config.
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
<add input="{URL}" pattern="^/blog/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
The result is like below:
I have the following rules. The second works but the first doesn't seem to to fire. For example, URL in question for the first rule is index.cfm?section=artists.az&id=22707 and for the 2nd rule which works, the URL is index.cfm?section=artists&id=22707
<rule name="Artists: AZ" stopProcessing="true">
<match url="^index\.cfm$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^section=artists\.az&id=([^=&]+)$" />
</conditions>
<action type="Rewrite" url="artist.php?id={C:1}" appendQueryString="false" />
</rule>
<rule name="Artists: index.cfm" stopProcessing="true">
<match url="^index\.cfm$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^section=artists&id=([^=&]+)$" />
</conditions>
<action type="Rewrite" url="artist.php?id={C:1}" appendQueryString="false" />
</rule>
ANy ideas?
I am using the URL Rewrite feature in IIS7 to turn the URL:
/main.asp?category=Name_Of_A_Product
Into:
/category/name-of-a-product/
I have created the redirect & rewrite rules below which do the majority of the work, except I cannot find a way of replacing the underscores with hyphens.
Each URL can have between zero and many underscores and I'm trying to replace them in a single regular expression, to avoid chains of 301 redirects (as I believe that is bad for SEO).
Do you know how (or if) this is can be done?
<rule name="Redirect REAL to FRIEDNLY" enabled="true" stopProcessing="true">
<match url="^main\.asp$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^category=([^=&]+)($|&(.*))$" />
</conditions>
<action type="Redirect" url="category/{ToLower:{C:1}}/" appendQueryString="false" />
</rule>
<rule name="Rewrite FRIEDNLY to REAL" stopProcessing="false">
<match url="^category/([^/]+)/?$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="main.asp?category={R:1}" />
</rule>
Unfortunately IIS7 has a few limitations:
you can only capture 9 groups C:1 ... C:9
there is only one string function and that's ToLower
Because of that you'll be limited to a URL with a maximum of 9 words separated by max 8 underscores (eg. /main.asp?category=One_Two_Three_Four_Five_Six_Seven_Eight_Nine) and you'll be forced to use 9 rewrite rules:
Single Word: /main.asp?category=Product
<rule name="Redirect REAL to FRIEDNLY 1" enabled="true" stopProcessing="true">
<match url="^main\.asp$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^category=([A-Za-z]+)$" />
</conditions>
<action type="Redirect" url="category/{ToLower:{C:1}}/" appendQueryString="false" />
</rule>
Two Words: /main.asp?category=Some_Product
<rule name="Redirect REAL to FRIEDNLY 2" enabled="true" stopProcessing="true">
<match url="^main\.asp$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^category=([A-Za-z]+)_([A-Za-z]+)$" />
</conditions>
<action type="Redirect" url="category/{ToLower:{C:1}}-{ToLower:{C:2}}/" appendQueryString="false" />
</rule>
Three Words: /main.asp?category=Some_New_Product
<rule name="Redirect REAL to FRIEDNLY 3" enabled="true" stopProcessing="true">
<match url="^main\.asp$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^category=([A-Za-z]+)_([A-Za-z]+)_([A-Za-z]+)$" />
</conditions>
<action type="Redirect" url="category/{ToLower:{C:1}}-{ToLower:{C:2}}-{ToLower:{C:3}}/" appendQueryString="false" />
</rule>
... ... ... ... ... ...