Forum Moderators: phranque
We like to have an Search Engine Save URL. Unfortunately, our Content Management System uses an URL like this:
<DomainName>/index.cfm?<Parameter>
The Parameter is an 32 Character String mixed with numbers and letters.
The new URL should look like this:
<DomainName>/index.cfm/<Parameter>
I spent days to find a running RegEx rule without any success.
Now I'm completly lost and real frustrated ;-)
We're using Apache 1.3.26 on Windows 2000.
Thanks for your help
Welcome to WebmasterWorld [webmasterworld.com]!
This thread [webmasterworld.com] is a good place to start, since it brings up several important points. The first is that mod_rewrite can be used to rewrite a static url to a dynamic url -- that is, to translate /a/b/c into /a?cat=b&prod=c for use in calling a script. However, the script itself must output the search-engine-safe URLs so that the search engines will see them. When the search engine (or a user) later requests a search-engine-safe URL, mod_rewrite will then convert it to the form needed for use by your scripts.
If your code doesn't work, please post the portion that is causing trouble and we will try to help you. However, we try not to do the work for you... We would rather help you to learn to fish for a lifetime, rather than giving you a fish to eat only today.
Jim
The link I provided above leads to a discussion of a problem that is only slightly more complex than yours.
However, you can replace a '/' with a '?', but not the other way around... mod_rewrite can do it either way, but only one makes sense on the server.
Perhaps it will make things clearer to show two complete HTTP request cycles, and to show *when* mod_rewrite is active. Assume that your script is named "a.cfm" and parameters are b & c:
HTTP request 1
client browser or search engine spider: GET /a/b/c
mod_rewrite: GET /a/b/c -> GET /a.cfm?cat=b&prod=c
script a.cfm: Create page using cat=b, prod=c, and serve this dynamically-generated page to requesting client (this page contains a link to /a/b/d)
HTTP request 2
client browser or search engine spider: GET /a/b/d
mod_rewrite: GET /a/b/d -> GET /a.cfm?cat=b&prod=d
script a.cfm: Create page using cat=b, prod=d, and serve this dynamically-generated page to requesting client (this page contains a link to /a/b/e)
et cetera...
----
mod-rewrite is active after the client request is received by the server and *before* the script is called or any content is served. Therefore it makes no sense to ask mod_rewrite to translate /a.cfm?cat=b&prod=c to /a/b/c *after* a client request but *before* a server response... it is not useful. The script must output 'safe' URLs, and mod_rewrite can be used to convert them back into calls to the script.
Jim
Yes, you're right. My point of view was from the other side :-)
The browser displays index.cfm/<param>, the rule will convert the url to index.cfm?<param>. I already changed all the links in my ColdFusion application.
I have full access to the server. I don't need to work with .htaccess.
My rule looks like this:
<Directory "D:/HTTPRoot/htdocs/mydomain.ch">
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)/(.*)$ $1index.cfm?$2
</Directory>
After calling the domain, all pathes are gone (No images, no styles). After clicking a link, i receive a 404 error.
I think Mr. Apache searches for a file <param>, funny.
RewriteCond {REQUEST_URI} !index.cfm
RewriteRule ^/([^/]*)/(.*)$ $1index.cfm?$2 [L]
The RewriteCond prevents a loop in case of an internal lookup.
Just as an example, this would rewrite
www.example.com/a/b to www.example.com/aindex.cfm?b
You can also extract contiguous numbers with ([0-9]*) and contiguous letters with ([a-zA-Z]*)
Jim
Thank you for your response.
To understand your example, I have read the mod_rewrite for dummies again. After that, i have a chance to modify your example to my needs.
I tried your example. I activated the RewriteLog to get some info. It looks not to bad. I received errors:
pass through D:\httproot\mydomain.com/$index.cfm
So, only the question markis too much :-)
By the way: Needs the module mod_rewrite a lot of CPU Power?
I tried your example. I activated the RewriteLog to get some info. It looks not to bad. I received errors:pass through D:\httproot\mydomain.com/$index.cfm
So, only the question markis too much :-)
I don't really understand what you mean. Are you using the [PT] flag on RewriteRule [httpd.apache.org] (pass through)? -- Like this:
RewriteRule ^/([^/]*)/(.*)$ /$1index.cfm?$2 [PT,L]
By the way: Needs the module mod_rewrite a lot of CPU Power?
Jim