cached mod_rewrite question

Discuss practical ways rearrange URLs using mod_rewrite.

cached mod_rewrite question

Postby ehappylucky05 » Wed Nov 05, 2008 11:59 am

Hi,
I am trying to find out how to use this third party mod_rewrite to redirect users to my cached html page, I have been trying to hack the provided .htaccess for 3 weeks, still have no luck, hope someone can help me with that, million thanks in advance!!!

Here is the situation, I've installed a 3 rd party program that will create a cached static pages for my website, and those cached static pages were created under the folder "cache"
The whole path to my website is http://www.example.com/whatever
so, the server path to the "cache" folder is

/webroot/whatever/cache

However, I was not able to get the .htaccess mod_rewrite to serve the user those cached static pages? Any idea on how to tweak the mod_rewrite below?

here is the questionable part of the 3 party .htaccess file
#######################

# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

# Modify the RewriteBase if you are using Dru in a subdirectory and
# the rewrite rules are not working properly.
RewriteBase /whatever


# Rewrite rules for static page caching provided by the 3rd party module:
# START
<IfModule mod_headers.c>
Header add Expires "Sun, 19 Nov 1978 05:00:00 GMT"
Header add Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
</IfModule>
<IfModule mod_mime.c>
AddCharset utf-8 .html
</IfModule>
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_COOKIE} !DRU_UID
# RewriteCond %{DOCUMENT_ROOT}/whatever/cache/%{SERVER_NAME}/0/index.html -f
RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/0/index.html -f
RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/index.html [L]
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{REQUEST_URI} !^/cache
RewriteCond %{REQUEST_URI} !^/user/login
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_COOKIE} !DRU_UID
RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/0%{REQUEST_URI} -d
RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/0%{REQUEST_URI}/index.html -f
RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/$1/index.html [L]
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{REQUEST_URI} !^/cache
RewriteCond %{REQUEST_URI} !^/user/login
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_COOKIE} !DRU_UID
RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/0%{REQUEST_URI}.html -f
RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/$1.html [L]

#END
#######################
ehappylucky05
 
Posts: 14
Joined: Tue Aug 19, 2008 8:02 am

Postby richardk » Wed Nov 05, 2008 1:51 pm

Please provide some examples of a URL and it's cache equivalent.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ehappylucky05 » Thu Nov 06, 2008 10:34 am

richardk wrote:Please provide some examples of a URL and it's cache equivalent.



Hi Richard,
The 3rd module will do this
#################
http://mysite.com/
=> cache/mysite.com/index.html

http://mysite.com/about
=> cache/mysite.com/about.html

http://mysite.com/about/staff
=> cache/mysite.com/about/staff.html

http://mysite.com/node/42
=> cache/mysite.com/node/42.html

###################

Since I am adding 1 subdirectory under the root directory, for example , the directory will be called "whatever"

the htaccess file should work like this
#######################
http://mysite.com/whatever/
=> cache/mysite.com/0/index.html

http://mysite.com/whatever/about
=> cache/mysite.com/0/about.html

http://mysite.com/about/staff
=> cache/mysite.com/0/about/staff.html

http://mysite.com/node/42
=> cache/mysite.com/0/node/42.html

#######################

But somehow, it doesn't work, any idea?
Thanks in advance!
ehappylucky05
 
Posts: 14
Joined: Tue Aug 19, 2008 8:02 am

Postby richardk » Fri Nov 07, 2008 11:43 am

The 3rd module will do this
#################
http://mysite.com/
=> cache/mysite.com/index.html

http://mysite.com/about
=> cache/mysite.com/about.html

http://mysite.com/about/staff
=> cache/mysite.com/about/staff.html

http://mysite.com/node/42
=> cache/mysite.com/node/42.html

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/cache/mysite.com/index.html -f
RewriteRule ^$ /cache/mysite.com/index.html [L]

RewriteCond %{REQUEST_URI} ^(/.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}/cache/mysite.com%1.html -f
RewriteRule !^cache(/.*)?$ /cache/mysite.com%1.html [L]


Since I am adding 1 subdirectory under the root directory, for example , the directory will be called "whatever"

the htaccess file should work like this
#######################
http://mysite.com/whatever/
=> cache/mysite.com/0/index.html

http://mysite.com/whatever/about
=> cache/mysite.com/0/about.html

http://mysite.com/about/staff
=> cache/mysite.com/0/about/staff.html

http://mysite.com/node/42
=> cache/mysite.com/0/node/42.html

#######################

I don't get it. Why do they all have /0, even without /whatever?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ehappylucky05 » Tue Nov 11, 2008 8:43 am

hi richard,
thanks for your reply, I don't know why they all have /0, even without /whatever, my guess is they try to standardize the subdirectory tree, which we can modified if we wanted to or if we can get it to work

I've tried the original code you've provided, and also added the "whatever" in your code as shown below, but still not working

#########################
RewriteCond %{DOCUMENT_ROOT}/whatever/cache/mysite.com/index.html -f
RewriteRule ^$ /whatever/cache/mysite.com/index.html [L]

RewriteCond %{REQUEST_URI} ^(/.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}/whatever/cache/mysite.com%1.html -f
RewriteRule !^cache(/.*)?$ /whatever/cache/mysite.com%1.html [L]
#########################

I apologize if I didn't make the previous posting clear, the cached folder is under the whatever directory,
hope below example provide a better idea

http://mysite.com/whatever/about/staff
=> /webroot/whatever/cache/mysite.com/0/about/staff.html

http://mysite.com/whatever/node/42
=> /webroot/whatever/cache/mysite.com/0/node/42.html

thanks in advance!
ehappylucky05
 
Posts: 14
Joined: Tue Aug 19, 2008 8:02 am

Postby richardk » Wed Nov 12, 2008 12:38 pm

Please post your examples again with the full path to the cache files.
What is your document root?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ehappylucky05 » Wed Nov 12, 2008 12:58 pm

richardk wrote:Please post your examples again with the full path to the cache files.
What is your document root?


Thanks a lot!
Last edited by ehappylucky05 on Mon Nov 17, 2008 8:54 pm, edited 1 time in total.
ehappylucky05
 
Posts: 14
Joined: Tue Aug 19, 2008 8:02 am

Postby richardk » Wed Nov 12, 2008 1:04 pm

I didn't really need that original mod_rewrite.

#######################
http://mysite.com/whatever/
=> /srv/www/htdocs/whatever/cache/mysite.com/0/index.html

http://mysite.com/whatever/about
=> /srv/www/htdocs/whatever/cache/mysite.com/0/about.html


http://mysite.com/whatever/about/staff
=> /srv/www/htdocs/whatever/cache/mysite.com/0/about/staff.html

http://mysite.com/whatever/node/42
=> /srv/www/htdocs/whatever/cache/mysite.com/0/node/42.html

#########################

What about /about/ and /node/42/?
And could you do one example of /another_dir/something? Just so i can be sure how this works, i think i get it now.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ehappylucky05 » Wed Nov 12, 2008 1:17 pm

Hi Richard,
Thanks for your prompt reply. Sure, I can do /about/ and /node/42/, the reason why I included the "whatever" sub folder, is because in my case, my program will have to reside under the "whatever" folder, I have no top web root access, in other word, I only have access to
/srv/www/htdocs/whatever/, but the domain will still be the same.

Ok, here is the example, supposedly, if I can have the web root privilege, the redirect should point to the path below
#######################

http://mysite.com/
=> /srv/www/htdocs/cache/mysite.com/index.html

http://mysite.com/about
=> /srv/www/htdocs/cache/mysite.com/about.html

http://mysite.com/about/staff
=> /srv/www/htdocs/cache/mysite.com/about/staff.html

http://mysite.com/node/42
=> /srv/www/htdocs/cache/mysite.com/node/42.html

############################

since I have no web root access, but I do have full privilege under the "whatever" directory, the redirect should point to the links as shown below
#######################
http://mysite.com/whatever/
=> /srv/www/htdocs/whatever/cache/mysite.com/0/index.html

http://mysite.com/whatever/about
=> /srv/www/htdocs/whatever/cache/mysite.com/0/about.html


http://mysite.com/whatever/about/staff
=> /srv/www/htdocs/whatever/cache/mysite.com/0/about/staff.html

http://mysite.com/whatever/node/42
=> /srv/www/htdocs/whatever/cache/mysite.com/0/node/42.html

#########################

Hope this clarify the situation
Thanks a lot again!
ehappylucky05
 
Posts: 14
Joined: Tue Aug 19, 2008 8:02 am

Postby richardk » Wed Nov 12, 2008 1:57 pm

Right. Try the following in a .htaccess file in /whatever
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond /srv/www/htdocs/whatever/cache/mysite.com/0/index.html -f
RewriteRule ^$ /whatever/cache/mysite.com/0/index.html [L]

RewriteCond %{REQUEST_URI} ^(/.*[^/])/?$
RewriteCond /srv/www/htdocs/whatever/cache/mysite.com/0%1.html -f
RewriteRule !^cache(/.*)?$ /whatever/cache/mysite.com/0%1.html [L]


Or, if you want it in /.htaccess, replace
Code: Select all
!^cache(/.*)?$

with
Code: Select all
!^whatever/cache(/.*)?$

and
Code: Select all
^$

with
Code: Select all
^whatever/$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 25 guests

cron