Forum Moderators: phranque
Basically I have my website using SEO URL's this way:
http://www.example.com/blog/archives.cfm/category/adobe
Which in reality is: http://www.example.com/blog/archives.cfm?category=adobe
What I would like to do is:
When a user hits this URL, he'd be shown a published flat HTML file I've already generated.
I've already accomplished it on the blog folder, by doing:
RewriteRule ^blog/$ /blog/published/index.html [L] By logic for my other file I tried:
RewriteRule ^adobe$ /blog/published/adobe.html [L] But that doesn't seem to work. Can somebody help me with this rewrite?
Thanks in advance,
Marcos Placona
[edited by: jdMorgan at 4:15 pm (utc) on May 20, 2009]
[edit reason] example.com [/edit]
Similarly, your first rule matches only exactly "/blog/" and nothing else.
Take a look at the regular-expressions tutorial cited in our Apache Forum Charter [webmasterworld.com] and specifically look into the concept of "anchoring" for more information.
As for your larger problem, try searching WebmasterWorld for "rewrite URL to script rewriterule" and similar keyphrases.
There are also several threads in our Apache Forum Library which may be quite helpful. Among them, the thread titled Changing Dynamic URLs to Static URLs [webmasterworld.com] may be most useful to you.
Jim
In "^adobe$ matches only the exact URL-path "/adobe" case, it's totally fine, but it doesn't seem to work. /adobe is only part of the url, and as you can see, the file itself is called archives.cfm, but only when it comes followed by the string "/category/adobe" I want to redirect to "/blog/published/adobe.html"
It all seems right in my optinion, but when i hit this file, nothing happens, it it still doesn't load the flat html file.
Thanks again
This is the logical contradiction that is apparently preventing your rule from working.
The pattern must match the URL-path part of the requested URL in order for the rule to be invoked. If "'/adobe' is only part of the URL," then your pattern won't match; It will match if and only if the requested URL is example.com/adobe, no more, no less.
Based on what you posted above, I'd say you need to add "blog/archive\.cfm/" ahead of "adobe" in your new rule's pattern, and put this new rule ahead of the generic /blog rewrite, so that the specific /abode rule is invoked first.
Again, I suggest a careful review of regex "anchoring."
Jim
[edited by: jdMorgan at 5:31 pm (utc) on May 20, 2009]
RewriteRule ^blog/archives\.cfm/category/([a-zA-Z0-9-]+) /blog/published/category/$1.html [R,L]. It then lead me to two new questions:
It really redirects to the html page now. What I wanted to accomplish was "read" from the HTML page, but still remain at the same URL. I tried to mix and match different combinations such as [PT,L], [NC,L], but the only one that seemed to load my published page was [R,L].
The other problem I have, is that I have a script that does http requests in a dayly basis to my pages, in order to grab all the HTML generated, and save on my published folder. It's all fine, but if I have this rewrite in position, when my http request tried to "hit" http://www.example.com/blog/archives.cfm/category/adobe, it will automatically be redirected to the already published page, as it'll fall into the rewrite.
I know some about RewriteCond, and I was wondering is there's any way I could check the request, to know if it's coming from my own server, or if it's coming from anywhere else.
RewriteCond %{REMOTE_ADDR} !^my_server's_ip$ before my RewriteRule, and it did the trick. now I'm only stuck on the first problem, which is:
Why is it doing the redirect to the html page. I just wanted to display the html page, but still stay at the same URL.
Cheers
What you apparently want is an internal rewrite, and the syntax for that is different:
RewriteRule ^blog/archives\.cfm/category/([0-9A-Za-z\-]+)$ /blog/published/category/$1.html [L]
Jim
I did try without the R, but it simply doesn't do anything. i went further and tried to find similar problems, and found this blog post, which talks about something similar I think:
[petefreitag.com...]
I tried using PT, PT,L, L alone, but none of them work, as they keep loading the dynamic page instead of the flat one.
Am I missing anything here? Is there a workaround for this problem?
Thanks
http://www.example.co.uk/blog/archives.cfm/category/adobe
The rule I tried is:
RewriteRule ^blog/archives\.cfm/category/([a-zA-Z0-9\-]+)$ /blog/published/category/$1.html [L]
And by hiting the original URL, it should open the contents from:
http://www.example.co.uk/blog/published/category/adobe.html
But on the original URL.
Thanks
[edited by: jdMorgan at 4:35 pm (utc) on May 21, 2009]
[edit reason] example.co.uk [/edit]
What does Live HTTP Headers for Firefox have to say for this request?
Temporarily add the [R] flag back in just to ensure that the rule is generating the right filepath (you will see the URL change -- look at it and make sure the path part is the right one), and then take it back out again.
#request# GET http://www.example.co.uk/blog/archives.cfm/category/adobe
GET /blog/archives.cfm/category/adobe
If I put R back, it will do something like:
#request# GET http://www.example.co.uk/blog/archives.cfm/category/adobe
GET /blog/archives.cfm/category/adobe
#request# GET http://www.example.co.uk/blog/published/category/adobe.html
But then it's doing two requests, which is not performant, and goes to a url I didn't wanna show.
But that means it's going to the right path, but not doing the internal rewrite
Thanks in advance
[edited by: jdMorgan at 4:36 pm (utc) on May 21, 2009]
[edit reason] example.co.uk [/edit]
If you're on Apache 2, disable AcceptPathInfo (See Apache core directives documentation).
Disable content negotiation/MultiViews if you've got them enabled and don't need them (use "Options -MultiViews").
Put the rule back in "internal rewrite" form, try the /blog/archives.cfm/category/adobe URL again, and check your error log for any warnings.
Review all of your .htaccess files, and make sure that there is/are no other rule(s) which interfere with or countermand this rewrite.
Jim
You say that your request "does not pull content." What happens if you change the rewrite to point to a simple "hello world" HTML file --say, in your Web root directory-- a file that has no dependencies on anything else (no scripts, no includes, no images, no css, no JS), just a static file that you have placed there...
I guess my summary of the above would be, "Stop changing the code and the server config, and instead test the set-up that you have very thoroughly, using all of the tools available."
Jim