Reputation: 45
I want to rewrite the url in my lucee application. I use the url "http://localhost:8888/sampleApp/views/test.cfm" to display the view pages and I want it to display as "http://localhost:8888/sampleApp/test.cfm".
Upvotes: 1
Views: 759
Reputation: 7563
Are you using IIS on Windows? If so all you need is the URL Rewrite Module 2.0
Install that, set up your web.config
with your rewrite rules and you're good to go.
You will also probably not want the .cfm
extension in your URLs. I use this rule for that:
<rule name="Rewrite .cfm" enabled="true" stopProcessing="false">
<match url="[^?]*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^(.*).png" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^(.*).cfm" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^(.*).cfc" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^(.*).jpg" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^(.*).gif" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^(.*).mp4" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^(.*).mp3" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^(.*).css" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.cfm" />
</rule>
You would have add to more conditions for all file types your website supports like .mkv
or .js
Upvotes: 1
Reputation: 1138
As already mentioned, this is up to the webserver to do, especially in production. However, in some cases and for development you may want to use urlrewrite in your servlet container engine without a fronted webserver. Reading from your post, you are using port 8888, and that makes me assume you are using Lucees default servlet container Tomcat.
Since Tomcat 8.0 it is possible to use urlrewrite. But as already said, this is only recommended for development or with Tomcat as stand alone in production. If you have another webserver in front of Tomcat you would let this settings untouched and the fronted webserver would do the url rewrite. For a working solution with Tomcat in stand alone, add the RewriteValve and a rewrite.config file containing the url rewrite rules as follows:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
...
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
...
</Host>
RewriteCond %{SERVLET_PATH} !-f
RewriteRule ^\/sampleApp\/(.*)\.cfm(.*)$ sampleApp/views/$1.cfm$2 [L,QSA]
You'll very probably have to tweak this rule. For more and deeper information, please see: Apache Tomcat 9 Rewrite Valve
Upvotes: 3
Reputation: 1069
That would not be implemented in Lucee, it would be done in the web server, e.g. Apache, IIS, Nginx, etc... Lucee is a servlet running on an application server like Tomcat, not the web server, do not conflate the two.
Upvotes: 3