I would like to convert this web.config
<rule name="cambiarPass" stopProcessing="true">
<match url="^cambiarPass/" />
<action type="Rewrite" url="modulos/cambiarPass/controller.php" appendQueryString="false" />
</rule>
to .htaccess. Please help!
Bear in mind that I do not use IIS but the provided code seems pretty self-explanatory in terms of how it should be converted to an Apache rewrite rule.
The <match url="^cambiarPass/" /> line is set to apply URL rewriting only to URLs (paths) which begin with cambiarPass/. The
<action type="Rewrite" url="modulos/cambiarPass/controller.php" appendQueryString="false" />
line is the one doing the rewriting and redirecting all matched URLs to modulos/cambiarPass/controller.php. The appendQueryString attribute is obviously a synonym for the Apache QSA rewrite flag meaning the rewrite process will discard and ignore any existing query string data during the rewrite. The stopProcessing attribute seems to be yet another equivalent for the Apache L rewrite flag meaning if this rule is matched any additional rewrite rules that might follow the current rule will simply be ignored.
Here is the complete code.
RewriteEngine on
RewriteRule ^cambiarPass/ modulos/cambiarPass/controller.php [L]
Related
I am moving a site from IIS 7 to Apache 2.4 and have the following web.config rewrite rule I am having trouble converting to .htaccess. The rule essentially allows for clean (seo friendly) urls by rewriting all files without an extension with the .cfm extension (e.g. www.mydomain/bag rewrites on the server as www.mydomain.com/bag.cfm. The working rule in web.config is shown below
<rule name="Rewrite all non extension requests to .cfm" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}.cfm" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="{R:1}.cfm" />
</rule>
I have tried all the like posts I could find on here and unfortunately none of them worked for me. I am running Lucee 5.0 on CentOS 7 (Apache 2.4) if that matters. Any guidance would be greatly appreciated.
I don't really know about Tomcat; I assume you need Apache because Tomcat's no good for serving your non-script content.
You could set them up so that they both have the same document root, thus have congruent URLs, but have Tomcat listening on a different port, and not have that port open externally. Then you could proxy requests that are for (hidden) cfm files like so:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.cfm -f
RewriteCond %{THE_REQUEST} ^\S++\s++([^?\s]++)(\?\S*)?
RewriteRule ^ http://127.0.0.1:8080%1.cfm%2 [NS,NE,P]
RewriteRule (?<=.cfm)$ http://127.0.0.1:8080/404.cfm [NS,NE,P]
The second rule is an example to pretend that the cfm files are not there if request directly.
You will need the appropriate proxy module(s) enabled.
I am trying to convert from using web.config on IIS to .htaccess on apache.
Although, i've got everything working, but got stuck on one thing.
<rule name="Imported Rule 2">
<match url="^blog/([a-zA-Z0-9_-]+)(|/)$" ignoreCase="false" />
<action type="Rewrite" url="index.php?url=blog&id={R:1}" appendQueryString="false" />
</rule>
I am trying to convert the above code into .htaccess.
If anybody could help, it would be gratefully appreciated.
Try to add this config to .htaccess
RewriteEngine on
RewriteRule ^blog/([a-zA-Z0-9_-]+)(|/)$ index.php?url=blog&id=$1
I saw some examples on how to convert IIS to htaccss.
I'm using httpd conf (for performance reasons) + i used online converter for IIS --> htaccess.
when converting this rule:
<rule name="videorecords URL" patternSyntax="Wildcard">
<match url="videorecords/*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="videorecords/{R:1}" />
</rule>
to:
#RULE VIDEORECORDS URL
RewriteRule videorecords/* videorecords/$1 []
the apache doesnt load and i see in the logs:
Syntax error on line 211 of httpd.conf: RewriteRule: unknown flag ''
Your flags are blank: []. So you need to either add a flag in ther (like L) or remove the square brackets.
Though, I don't think that the rewrite rule online converter gave you is actually what you want.
With IIS7, URL Rewrite 2 there is an MVC4 application APP on server SRV. The following rewrite should happen.
http://SRV/APP into http://SRV/APP/
I tried by creating the AddTrailingSlash rule. However, it does not work for the application's root. It does work for directories under the root, so the following rewrite is done
http://SRV/APP/pipapo into http://SRV/APP/pipapo/
What has to be done so the rewrite also works for the root?
The following rule seems to work for me:
<!--Add trailing slash to root non-file url-->
<rule name="Add trailing slash" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<!--Match uri's missing trailing slash-->
<add input="{PATH_INFO}" pattern="(.*[^/])$" />
<!--Ignore any uri containing a period (probably a better way to do this but IsFile was not behaving as expected for me)-->
<add input="{PATH_INFO}" pattern="(.*?)\.(.*?)" negate="true"/>
</conditions>
<action type="Redirect" redirectType="Permanent" url="{PATH_INFO}/" />
</rule>
By default, the built in add trailing slash does not apply to directories or filenames... If you want it to apply to directories (like in the above example http(s)://srv/app), you have to modify the rule and delete the Condition that has "Type: Is Not a Directory". Don't forget to apply...
Happy URL Rewriting! :)
I was wondering if there is a way to handle in a rewrite rule ( iis and apache ) url query strings which contain a slash ( %2F ) as part of it.
as an example:
www.domain.com/project/word1
gets rewritten to
www.domain.com/project/index.php?word=word1
via this rule ( in iis ):
<rule name="Friendly">
<match url="^(.+)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?word={R:1}" appendQueryString="false" />
</rule>
or in apache:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?word=$1
this works correctly.
however there are cases like this :
www.domain.com/project/word1%2Fword2
which should be redirected to
www.domain.com/project/index.php?word=word1/word2
but obviously i get an error 404 because of the slash ( %2F ). Is there any way to solve this ? Even if it meant I have to cut off the /word2 part and redirect www.domain.com/project/word1%2Fword2 to www.domain.com/project/index.php?word=word1
thank you in advance
I find your case peculiar because in Apache's mod_rewrite module (I'm not sure about IIS) it's stated that RewriteRule patterns are matched against the, I quote, "(%-decoded) URL-path (or file-path, depending on the context) of the request".
What I'm experiencing though after testing is that the encoded slashes are not decoded or not interpreted by the server (I too get an 404 error).
However, I realize one mostly url encode URL parts when the content is to be used as a query string argument (for example http://www.example.com/?path=word1%2Fword2) which is logical because you don't want the server to interpret the encoded slash as a part of the URL path. Note that this observation is contradictive to the statement above so take it with a grain of salt.
Solution
What I can confirm however is that it's no problem rewriting www.domain.com/project/word1/word2. Therefore I suggest that you don't encode the pat of the URL that will be used in the path part, but possibly whitelist allowed characters instead so you avoid special characters like ?.
Test results
.htaccess:
RewriteRule ^(.+) index.php?word=$1 [L]
index.php:
<pre>
<?php var_dump( $_GET, true ); ?>
</pre>
URL: http://test/word1%2Fword2
Yields 404.
URL: http://test/word1/word2
Yields:
<?php
array (size=1)
'word' => string 'word1/word2' (length=11)
?>