Ticket #238 (closed task: completed)

Opened 13 months ago

Last modified 7 months ago

Implement writing route URL rewrite rules to a file for UrlRoutesProperty

Reported by: peterfarrell Owned by: kurtwiersma
Priority: critical Milestone: Mach-II 1.8.0 alpha
Component: framework - core Version: 1.8.0 - Framework
Keywords: UrlRoutesProperty route buildRoute routes URL rewrite rules Apache Cc:
Blocking: Blocked By:

Description

Implement writing route rewrite rules to a file for UrlRoutesProperty. We can use "smart" defaults for location to write the route URL rewrite rules to a file however we should provide parameters in the property to direct where that should happen if desired. I'm thinking of writing them in a subdirectory of the /config folder like /config/rewriteRules/nameOfModule.txt. We should use the module name in cause they have the property defined in a module as well.

Attachments

Change History

Changed 11 months ago by kurtwiersma

  • status changed from new to assigned

The goal here is to create Apache mod_rewrite rules that eliminate the need for /index.cfm/ in the normal route urls.

RewriteRule ^/route1/([A-Za-z0-9-]+)/?$ /index.cfm/route1/$
RewriteRule ^/route2/([A-Za-z0-9-]+)/?$ /index.cfm/route2/$

A new property called urlRouteBase will be created so people can say routes don't have a url base while normal BuildUrls? use the value from urlBase. if you don't specify a urlRouteBase property it defaults to the vallue in urlBase.The default "urlBase" argument to buildUrlRoute will then default to the value in urlRouteBase property.

Changed 11 months ago by peterfarrell

Kurt I think the replacement expression needs to indicate the replacement for the:

RewriteRule ^/route1/(.*)$ /index.cfm/route1/$1 [PT,L]
RewriteRule ^/route2/(.*)$ /index.cfm/route2/$1 [PT,L]

I think we just need to pass through everything after the route name and the [PT,L] means this is the only regex pattern that matches this (basically so mod_rewrite doesn't keep searching for a better match once it finds a match).

Changed 11 months ago by peterfarrell

I should say that I'll need to test that regex.

Also, I think we need to urlRouteBase property that defaults to the value of the urlBase property if it isn't not defined. This new property just like urlBase will inherit from the base if in a module.

We'll also have to add in a flag to turn on the feature that writes out the rewrite rules and a location to write the file. I was thinking of file names mach-ii_rewriteRules.txt and mach-ii_rewriteRules_nameOfModule.txt if it's a module. That way we can independently manage the rules per module.

Changed 9 months ago by kurtwiersma

Initial support committed to SVN. Peter could you review this? We should chat about any additional features. I got it working nicely to write a good .htaccess file for me that had the rules in it I needed.

Changed 9 months ago by peterfarrell

Kurt, I think it's looking good. FYI, I switched to use the a mutable character builder instead of building up a string in CFML because it's faster to it with a Java class. See #315 for more information.

I think that using the appRoot isn't going to work to build the rewrite rules. For example I have an application the sits in the web root, but the config and module are above the web root (using a mapping). It produces rules like this:

RewriteEngine on
RewriteRule ^/spectrum/fsc-oak-flooring/(.*)$ /spectrum/index.cfm/fsc-oak-flooring/$1 [PT,L]
RewriteRule ^/spectrum/bamboo-flooring/(.*)$ /spectrum/index.cfm/bamboo-flooring/$1 [PT,L]

This don't work because they need to be like:

RewriteEngine on
RewriteRule ^/fsc-oak-flooring/(.*)$ /index.cfm/fsc-oak-flooring/$1 [PT,L]
RewriteRule ^/bamboo-flooring/(.*)$ /index.cfm/bamboo-flooring/$1 [PT,L]

So I think the solution is to use the Mach-II property urlBase and the CFML function getDirectoryFromPath.

Also, I think it would be nice to simply the config file configuration. To just use a default file name:

<parameter name="rewriteConfigFile">
	<struct>
		<key name="rewriteFileOn" value="true" />
		<!-- File path is optional -->
		<key name="filePath" value=".rewriteRules_moduleName" />
	</struct>
</parameter>

Instead of using .htacess (which is slow when you turn it on), people can just do an Apache include:

Include /pathTo/rewriteRules_*.cfm

I'm thinking that we do some special stuff and write the rules to a .cfm file for "security". Also, we should add some comments in there as well such as module name and date generated. We could do this:

## <cfsetting enabledCfoutputOnly="true"/>
## Date Generated: 6/9/2009 23:55:00
## Module Name: base

RewriteEngine on
RewriteRule ^/fsc-oak-flooring/(.*)$ /index.cfm/fsc-oak-flooring/$1 [PT,L]
RewriteRule ^/bamboo-flooring/(.*)$ /index.cfm/bamboo-flooring/$1 [PT,L]

## <cfsetting enabledCfoutputOnly="false"/>

We'd need the double ## in case somebody tries to invoke the rules file URL from a browser (if it's in the web root or lower).

Changed 9 months ago by kurtwiersma

(In [1622]) Added some smart defaults to the rewrite file routine. refs #238

Changed 9 months ago by kurtwiersma

  • status changed from assigned to closed
  • resolution set to completed

Add/Change #238 (Implement writing route URL rewrite rules to a file for UrlRoutesProperty)

Author


E-mail address and user name can be saved in the Preferences.


Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.