Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

All dynamic site rewrite to static URLs

(Page 1 of 2)
> >
Quote Reply
All dynamic site rewrite to static URLs
Hi

I'm having a great deal of fun discovering the ins and outs of rewrite rule and I thought I only had one two issues left...

I want to have a dynamic site using rewrite on look static. So I’ll have page.cgi and other scripts dynamically creating the pages and rewrite on will create URLs that look static.

I came across the issue that if I used d=1 to indicate I wanted dynamic pages that I couldn’t get the rewrite rules to work properly. For example when I generate www.sitename.com/mag/articles/article_name_L1.html with no d=1 then I get this exact link and it works but if the page linking to it has d=1 activated then I will get www.sitename.com/cgi-bin/page.cgi?g=mag/articles/article_nameL1.html;d=1 instead.

Now however I’m realizing that this may just become unrealistic in that I have both category.html and new.html and maybe others that are generating files that are either dynamic when I use d=1 (with the above issues) or static and don’t point to the right place since I only have dynamically generated pages….

For example for the category “others” I will have in category.html without d=1 :
www.sitename.com/others/index.html
whereas I’d like to have :
www.sitename.com/mag/others/index.html
so that my rewrite rule kicks in:
RewriteRule ^/mag/(.*)$ /cgi-bin/page.cgi?g=$1

but I'm guessing this will lead me down a road where I need to modify the core code in order to be able to have the whole site dynamically created but to look static.
I was thinking I could also to a redirect of :
/others/* to /mag/others so that then the rewrite on would kick in but it seems a bit of an overkill server-side.

I’m wondering whether a) I’ve got the wrong rewrite rules and that there is a way to have d=1 activated or b) I’m looking at this the wrong way or c) the dynamic cloaked solution is not going to work ?

Any wise advice would be greatly appreciated

Thanks, John
Significant Media
Quote Reply
Re: [Jag] All dynamic site rewrite to static URLs In reply to
Hi,

You generally don't need d=1 passed in at all. If you:

a. Set your build_root_url to http://domain.com/mag/
b. Setup a rewrite rule:

RewriteRule /mag/?(.*) /cgi-bin/page.cgi?g=$1 [L]

That's all you need. All the URL's Links SQL creates will be static (new, cool, category, home, etc), and rewrite will automatically send it to page.cgi.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] All dynamic site rewrite to static URLs In reply to
Thanks Alex I think I'm starting to understand how the rewrite works and your comments have helped me understand how Links works in intercepting the urls.

I think the only thing I'm unsure about is how to handle the different tags that page.cgi can handle and differentiate between them.

In effect I have this in my conf file :

1) RewriteRule ^/mag/(.*)$ /cgi-bin/page.cgi?g=$1
2) RewriteRule ^/magazine/(.*).html$ /cgi-bin/page.cgi?p=$1
3) RewriteRule ^/page/(.*).html$ /cgi-bin/page.cgi?page=$1

(the third one is for a page that displays editors with yogi's pagebuilder)

The problem is that the same cool catch on the fly system (my simple understanding) that you refer to if I set the build_root_url to 1) domain.com/mag/ seems to catch everything and rewrite the first part.

Ex :
domain.com/magazine/start.html needs to go to /cgi-bin/page.cgi?p=start.html
but with the above setting it gets rewritten to :
domain.com/mag/magazine/start.html and thus goes to /cgi-bin/page.cgi?g=start.html and I get a big error (well an error) :

Error

Oops, we had the following problem:

Category 'magazine/start.html' does not exist.

So I may be mistaken but as soon as I want to use a custom template I'm stuckBlush.

Thanks John
Significant Media
Quote Reply
Re: [Jag] All dynamic site rewrite to static URLs In reply to
Hi,

If you also want custom pages passed in, just decide on the URL structure you want. i.e. you could setup the following structure:

http://domain.com/ -> Links SQL Generated Home Page
http://domain.com/page.html -> Links SQL Generated Custom Page named page.html
http://domain.com/mag/Category/ -> Links SQL Category
http://domain.com/mag/Detailed/123.html -> Links SQL Detailed Page
...

To achieve the above URL structure using all dynamic pages, you just need to:

a. Set build_root_url to http://domain.com/mag/
b. Add the following rewrites:

RewriteRule ^/?$ /cgi-bin/page.cgi [L]
RewriteRule ^([a-zA-Z0-9-]+)\.html /cgi-bin/page.cgi?p=$1 [L]
RewriteRule ^/mag/(.*) /cgi-bin/page.cgi?g=$1 [L]

If it's in an .htaccess in your document root, you may also need to change [L] to [L,PT] depending on how you are setup.

Hope that helps,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] All dynamic site rewrite to static URLs In reply to
Alex,

I've found that to use the static rewrite, you need to check the box "update others" so that the new, cool, etc paths also point to the /rewritten/ directory. Otherwise, you get a category not found error.
You can also do that manually, but it's tedious.

After dong that, you need to set your image directory back to where it was.

With the 2.99, you have to reset the static directory paths as well.

But, all my sites are using the static-look dynamic generation.

I might be using different rewrite rules, but they are the ones we worked out years ago :)

Code:
RewriteRule ^/$ /newdir/ [R,L,NC]
RewriteRule ^/newdir/?$ /newdir/

<Directory /home/user/domain.com/www/newdir/>
Options All -Indexes -FollowSymLinks +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule (.*) /cgi-bin/links/page.cgi?g=$1 [L]
AllowOverride All
Allow From All
</Directory>


This is in the httpd.conf/domain config files, not an .htaccess

I prefer that set up, since .htaccess files can lead to confusion, and once set up, this should never have to change.

There are duplicate RewriteEngine On lines.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] All dynamic site rewrite to static URLs In reply to
Hi,

Yes, you should have New, Cool, Detailed all contained within your build_root_url so that the rewrite catches it. Also, you don't want any static content like images hitting a rewrite which is why it's much easier to use http://domain.com/mag/ versus http://domain.com/ (which can be done, just need to make the rewrite more complex and exclude specific things).

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] All dynamic site rewrite to static URLs In reply to
The New/Cool/etc are in the build_pages area, but still, get errors without doing it this way.

When I forget to change the related paths, I get those errors, when I edit them, they go away.

The above is the rewrite rule set that is working on all the sites.

I'll try modifying towards the other rules, on the next site I set up or modify, but over the years, any changes to this formula have "broken".

Again, I use this in the server-end config file, not in an .htaccess file.

I've always stored the images and other files in a root-level /images/ directory, so they are out of the way of any rewrite rules.

/images
..../LinksSQL
..../Gforum
..../OtherProgram
..../Clip-Art

Etc.

Just always seemed more logical to me to do it that way, so I could backup/notbackup the images, which often were HUGE rarely-if-ever-changing directories.

I'll have to modify the new GT "static" layout once it settles down, since I can understand putting the css and js in a static directory, but the images should be in the /images/ directory.

I don't think of images as "static" files, they are "images". "Static" files are unchanging code or data files. I'm too old a dog to change that conceptual separation. Maybe just ln them to the other images directory.

The problem with "change" is that it *is* change. I made major changes to a working layout to move to the "new" layout of the GT servers :), but I've always found the "pages/images" concept of Links more than a bit odd. Very often, images are shared between different programs, so they should be in a different tree. But, that's me. I started out as a pioneer in digital imaging, so I'm developmentally biased in that direction :)

I'm always looking for "better", not simply different. If a change works better, I'll incorporate it, but it's more important for me to know on a low-level the layout of the server, at 4 in the morning, when things are going crazy :)

I've tried to change/simplify the rules, but every time, they break, or they break something else. Maybe 3.0 will behave differently ?


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [Alex] All dynamic site rewrite to static URLs In reply to
Hi

Thanks for the clarification I was getting a bit lost with all the different variants I was trying... It now seems to work pretty well

As I was saying I hadn't understood the inherent catch on build_url domain and how elements drilling down within that folder where also up for catch ;)
So thanks for explaining that.

I did, like pudog explains, have to update all the urls in the update_others part in order to get it working but believe it or not I'd figured that out last night (well impressed with myself Cool).

I also set up a <%site_url%> value that I use to precede any html files that need to be redirected via this rewrite :

RewriteRule ^([a-zA-Z0-9-]+)\.html /cgi-bin/page.cgi?p=$1 [L]

example http://www.domain.com/home.html or http://www.domain.com/toppopular.html (Laura's stats plug-in trend ranking)

Instead of <%build_root_url%>/toppopular.html I just use <%site_url%>/toppopular.html otherwise if I use the build_root_url I obviously end up with :

http://www.domain.com/mag/toppopular.html
which is redirected to /cgi-bin/page.cgi?g=$1 instead of /cgi-bin/page.cgi?p=$1

Also as you stated in your mail by adding the pass though option it enables me to use the code in my httpd.conf file whereas before I was having to use .htaccess files which I agree with pugdog is far less interesting for organizing everything from one place...

Thanks ever so much for all this feedback Smile

I'm not sure it's a home run yet but I'm well on the way with all this help !

Thanks, John
Significant Media
Quote Reply
Re: [Jag] All dynamic site rewrite to static URLs In reply to
I have been trying to get this working all day.
I am currently checking with host to see if there is some problem there.
They have already told me that mod-rewrite is avail by default.

I am trying to do exactly what is in this thread.

My .htaccess file:
RewriteEngine On
RewriteRule ^/?$ /cgi-bin/links/page.cgi [L]
RewriteRule ^([a-zA-Z0-9-]+)\.html /cgi-bin/links/page.cgi?p=$1 [L]
RewriteRule ^/(.*) /cgi-bin/links/page.cgi?g=$1 [L]

FYI I have tried this in place of bottom line above to no avail:
RewriteRule ^/links_html/?(.*) /cgi-bin/links/page.cgi?g=$1 [L]

When mousing over "New", "Cool" etc... it shows url as:
http://www.supportmusicians.com/links_html/New/
Perfect!

When mousing over a Link Title, it shows url as:
http://www.supportmusicians.com/links_html/Detailed/Band_Websites/Easy_Chair_5.html
Perfect!

When clicking the link for any of the above, I get:
The requested URL /links_html/New/ was not found on this server.
or
The requested URL /links_html/Detailed/Band_Websites/Easy_Chair_5.html was not found on this server.

So it appears that mod rewite is not working at all. Am I correct?

Please.. Please... HELP!
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] All dynamic site rewrite to static URLs In reply to
Hi Chris,

What I found the most useful was Laura's feedback of using the [R] at the end of your mod_rewrite when I was having problems. This will actually tell you where the redirection is looking for /links_html/New/ at the moment using [L] or even the passthru [PT] value you will not see where it is being redirecting to, since the whole idea of the mod_rewrite is to mask this from users hence you get the impression it is looking for "http://www.yourdomain.com/links_html/New/" but it may be looking for http://www.yourdomain.com/cgi-bin/links/links/page.cgi?g=New and changing your rewrite rule to [R] 'should' show you this and thus give you a better idea.

Also pugdog talks about the modifications you need to make in the urls in the admin panel. Make sure you've changed them so that the path you specify for New has the /links_html/ before it. In Admin > Setup > Paths and URLs and click on the "click here" right at the bottom to check how the paths are set.

I think you'll find changing the rewrite rules to the value [R] at the end will help you figure things out the most.

Hope this helps :)

John
Significant Media
Quote Reply
Re: [Jag] All dynamic site rewrite to static URLs In reply to
Still doesnt work. You can check it out at supportmusicians.com

I have verified all urls have /links_html/ in them. I did NOT reset the static and image urls like pugdog said, but they appear correct http://www.supportmusicians.com/links_html/static

Mod_Rewrite does appear to be working for the default domain without anything behind the .com,
because I do not have any index in the root web directory, and I do get to the home page.

Current option is at [R], and the server is looking where it says it is.
Of course the files DONT exist, because they arent there. 100% dynamic.

So this must be a unix line-break issue or something, because it appears the the 1st line must be working.
RewriteEngine On
RewriteRule ^/?$ /cgi-bin/links/page.cgi [R]
RewriteRule ^([a-zA-Z0-9-]+)\.html /cgi-bin/links/page.cgi?p=$1 [R]
RewriteRule ^/links_html/(.*) /cgi-bin/links/page.cgi?g=$1 [R]

Thanks
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] All dynamic site rewrite to static URLs In reply to
I've just tried :
http://www.supportmusicians.com/home.html

which redirects to :
http://www.supportmusicians.com/cgi-bin/links/page.cgi?p=home

as your rewrite rule directs it to.


For New try this :

RewriteRule ^/links_html/(.*)$ /cgi-bin/links/page.cgi?g=$1 [R]

(I think you may need the dollar herre)

I'll keep my fingers crossed for you :)

John
Significant Media

Last edited by:

Jag: Apr 14, 2005, 8:24 PM
Quote Reply
Re: [Jag] All dynamic site rewrite to static URLs In reply to
Frown Nope, in place now.

Like I said, it seems as though it is not seeing 2nd and susequent RewriteRules. Only the first one, because that one works.
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] All dynamic site rewrite to static URLs In reply to
I think the example I gave you above shows that your first and second lines work. Just not the third :(
Well I must warn you I'm not a pro at this but by the look of it there is something wrong because it doesn't look as if it's redirecting anything.
The sloppy way I tested it myself was to actually create the physical directory and putting a file in there to see if that appeared when I typed New.

I also found that it was better not to use underscores unless it was a delimeter in the rules but I don't think it would have such an effect...

Sorry you've reached the limit of my knowledge here. Maybe take a look at your error logs ? But if it is something to do with the third line not working that most probably won't show you much.

In your place I'd try it with links instead of links_html and also with only that third line comment the others out. And your best bet is to wait for someone a bit more savvy with rewrite rules hoping what you tried will give them a good idea what is going wrong...

Cheers, John
Significant Media
Quote Reply
Re: [Jag] All dynamic site rewrite to static URLs In reply to
Cool, I'll try your suggestions. Thanks so much John.

I'll keep working on it.

Anyone else have any suggestions?

Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] All dynamic site rewrite to static URLs In reply to
One other thing I noticed that might help someone else figure it out.

When you type :
http://www.supportmusicians.com/links_html/

you get a forbidden 403 error which you usually get on cgi-bins

whereas both :
http://www.supportmusicians.com/links_html/New
and
http://www.supportmusicians.com/links_html/New/

gives you a 404 error which is weird since it's in links_html

This doesn't help you Chris but might get someone else thinking, maybe :)

John
Significant Media
Quote Reply
Re: [Jag] All dynamic site rewrite to static URLs In reply to
I had noticed the 403 error when clicking on "home" which takes you to:
http://www.supportmusicians.com/links_html/

I have triple-checked the permissions on links_html and they are at 777

Chris

RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [Jag] All dynamic site rewrite to static URLs In reply to
Quote:
In your place I'd try it with links instead of links_html and also with only that third line comment the others out. And your best bet is to wait for someone a bit more savvy with rewrite rules hoping what you tried will give them a good idea what is going wrong...

I have now changed the name of my link_html directory to "links" and updated all paths, still doesn't work.


10 hours and counting on these 4 f&*^&*^ lines of code!

current .htaccess:
RewriteEngine On
RewriteRule ^/?$ /cgi-bin/links/page.cgi [R]
RewriteRule ^([a-zA-Z0-9-]+)\.html /cgi-bin/links/page.cgi?p=$1 [R]
RewriteRule ^/links/(.*)$ /cgi-bin/links/page.cgi?g=$1 [R]

visit supportmusicians.com and try clicking on "Home" and "New" and "Cool"

Still get error:
The requested URL /links/Cool/ was not found on this server.

Irritated,
Chris

RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] All dynamic site rewrite to static URLs In reply to
Hi,

I've already replied to your other thread - try the this for your third rule:
RewriteRule ^links/(.*)$ /cgi-bin/links/page.cgi?g=$1 [R]
Quote Reply
Re: [afinlr] All dynamic site rewrite to static URLs In reply to
YEAH TEAM!

That last line fixed the problem. Mostly

Thank you so much!

These all work:
http://www.supportmusicians.com
http://www.supportmusicians.com/
http://www.supportmusicians.com/home.html
http://www.supportmusicians.com/links/Cool
http://www.supportmusicians.com/links/Cool/
http://www.supportmusicians.com/links/Band_Websites
http://www.supportmusicians.com/links/Band_Websites/

The following urls DO NOT work:
http://www.supportmusicians.com/index.html
http://www.supportmusicians.com/links/Detailed/Band_Websites/Bear_Creek_Band_6.html
The bottom url is created with...

Code:
<%if detailed_url and isValidated eq 'Yes'%>
<a href="<%detailed_url%>"><%elsif URL ne 'http://' and isValidated eq 'Yes'%>
<a href="<%config.db_cgi_url%>/jump.cgi?ID=<%ID%>"><%endif%>
<%if highlight%><%Links::Tools::highlight($Title,$query)%><%else%><%Title%><%endif%>
<%if isValidated eq 'Yes'%><%if detailed_url or URL ne 'http://'%></a><%endif%><%endif%>
I Think I can fix the "Detailed" issue, but can't try til I get home in about 8 hours :-)

Because this does work:
http://www.supportmusicians.com/links/Detailed/6.html

It would be nice for this to work:
http://www.supportmusicians.com/index.html

I will also try re-hooking up the ErrorDocument when I get home from work today.
I had disabled it to figure out rewrite.

Thanks again,
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] All dynamic site rewrite to static URLs In reply to
I'm baaaack :-(

I am still having some problems with Rewrite rule, but it is different now...
It is actually more of a CSS problem.

During the process of trying getting Rewrite to work,
I renamed the directory that GLinks saves html files to.
It used to be: www/http/links_html
I renamed it to: www/http/links

I updated ALL the paths and urls in the admin to reflect the change.

With the following rules in place, the site displays with correct CSS,
BUT I get a 404 Not Found error when clicking on New, Cool and others.
RewriteEngine On
RewriteRule ^$ /cgi-bin/links/page.cgi [L]
RewriteRule ^([a-zA-Z0-9-]+)\.html /cgi-bin/links/page.cgi?p=$1 [L]
RewriteRule ^links_html/(.*)$ /cgi-bin/links/page.cgi?g=$1 [L]

When I change the bottom rule to the "correct" directory (now 'links'),
The site displays without CSS, BUT New, Cool all work perfectly.

So, it is either NO CSS and working rewrite rules or
good CSS and broken rewrite.

There is a directory problem here. Somehow GLinks is STILL using the old directory for the CSS file.

The file in /cgi-bin/links/admin/Links/Config/Data.pm
contains the following line, which has the WRONG path.
'db_static_url' => 'http://www.supportmusicians.com/links_html/static',

I am reluctant to change this manually, but it is the only occurance of "links_html" I can find.
Are there files in a "compiled" folder somewhere that might be holding onto the old directory name?

That's all I have, except a headache from trying to figure this out :-)

Please help, this is becoming urgent.

Thank you,
Chris
www.supportmusicians.com
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] All dynamic site rewrite to static URLs In reply to
Update...

If I view the source code of the page with the correct rewrite rule in place
(All links work, but no css file is used):
RewriteRule ^links/(.*)$ /cgi-bin/links/page.cgi?g=$1 [L]

The browser is looking for the css file here:
<link type="text/css" rel="stylesheet" media="screen" href="http://www.supportmusicians.com/links/static/terra/terra.css" /> The CSS *does* reside there, so now I do not know what gives.
"terra" is a custom template set that inherits from luna.

Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] All dynamic site rewrite to static URLs In reply to
OK, best guess is that the following rewrite rule is intercepting the .css file.
RewriteRule ^links/(.*)$ /cgi-bin/links/page.cgi?g=$1 [L]

Can someone give me an example of how to rewrite this rule to skip
files that end in .css?

This may well be the problem.

Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] All dynamic site rewrite to static URLs In reply to
Hi,

Try this;

RewriteRule (.*)\.css$ $1.css [L]

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [rgbworld] All dynamic site rewrite to static URLs In reply to
You should try the same rewrite rule for the images they seem to be intercepted by some rule you have. Andy posted one he uses where you have images redirected to images like your css redirect...

John

Edit this is from Andy's post :

RewriteRule ^images/(.*) images/$1 [L]

http://www.gossamer-threads.com/...i?post=264001#264001
Significant Media

Last edited by:

Jag: Apr 16, 2005, 12:46 PM
> >