Forum Moderators: phranque

Message Too Old, No Replies

Probs with rewrite redirects

         

Markus Klaffke

10:28 pm on Oct 28, 2007 (gmt 0)

10+ Year Member



I have a problem with mod-rewrite rules. My blog software generates its content this way:
If a request for a website comes in, first a gateway.cgi script in /python-cms must be asked if the requested html page exists in the cache folder (/blog) or not. If it exists, the page will be fetched from the cache, if not it will be generated and saved in /blog. Thus the way is /blog and if nothing is found it goes to /python-cms/gateway.cgi. But The redirect to /python-cms/gateway.cgi doesn' t work.

1. Calling http://example.com should redirect me to http://example.com/blog or if there is no cached index.html, it should redirect me to http://example.com/python-cms/gateway.cgi to generate the missing index.html. But the result is now the index view of http://example.com.

2. If there is no index.html in /blog: Calling http://example.com/blog/ gives me the index view of /blog and does not redirect to /python-cms/gateway.cgi.

Above is my complete .htaccess file. It is very long, but maybe someone of the boards experts find the time to check it. If there are other errors or stuff that can be written better or is not needed, please let me know. Thansk in advance.

########################################
Additional infos:

My site structure is this:

DocumentRoot/python-cms
DocumentRoot/blog

..........................................

<Directory /var/www/klaffke/htdocs>
Options +ExecCGI +Includes +Indexes +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>

AddHandler cgi-script .cgi

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

I have a .htaccess file in /python-cms:

RewriteEngine on

RewriteCond %{HTTP_HOST} "^www"
RewriteCond %{HTTP_ACCEPT}!application/xhtml\+xml
RewriteRule ^(.*) http://example.com/blog/$1 [R=301,L]

RewriteCond %{HTTP_ACCEPT} application/xrds\+xml
RewriteCond %{HTTP_ACCEPT}!application/xrds\+xml\s*;\s*q\s*=\s*0(\.0{1,3})?\s*(,¦$)
RewriteRule ^$ http://example.com/public/yadis.xrdf [R,L]

RewriteCond %{HTTP_USER_AGENT} AdultGods
RewriteRule ^.* - [F]

#
# Ensure that POST requests and requests with query strings are not
# served from the cache.
#
RewriteCond %{QUERY_STRING}"!^$"[OR]
RewriteCond %{REQUEST_METHOD}"POST"[NC]
RewriteCond %{REQUEST_URI}"!^/python-cms/\w+.cgi"
RewriteRule (.*) /python-cms/gateway.cgi/$1[PT]

#
# Redirect all missing files to the CGI script
#
RewriteCond %{REQUEST_FILENAME}!-s
RewriteCond %{REQUEST_FILENAME}/index.html!-s
RewriteRule (.*) /python-cms/gateway.cgi/$1 [PT]

#
# The following needs to be maintained in synch with the templates:
# Add in the necessary headers when responses are served from the cache.
#

Header set X-Pingback http://example.com/blog/pingback

AddType text/xml rss ffkar opml soap sn2 tb tbrss wsdl xss
AddType text/plain txt esf
AddType application/atom+xml atom
AddType application/xhtml+xml xhtml
AddType application/rss+xml rss2 rss21 rss11
AddType application/rdf+xml rdf
AddType application/x-netcdf cdf

AddDefaultCharset utf-8
AddCharset utf-8 atom rss ffkar soap tb tbrss wsdl xss html
AddCharset utf-8 txt esf xhtml rss2 rss21 rdf cdf

#
# Serve up XHTML with the proper mime type to browsers that will accept it
#

RewriteBase /blog
RewriteCond %{REQUEST_FILENAME} /$
RewriteRule (.*) /blog/$1/index.html
#
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT}!application/xhtml\+xml\s*;\s*q=0\.?0*(\s¦,¦$)
RewriteCond %{REQUEST_URI} ^([^.]*¦.*\.html)$
RewriteRule .* - [T=application/xhtml+xml;charset=utf-8]
#
RewriteCond %{HTTP_ACCEPT} ^$
RewriteCond %{REQUEST_URI} ^([^.]*¦.*\.html)$
RewriteRule .* - [T=application/xhtml+xml;charset=utf-8]
#
RewriteCond %{HTTP_ACCEPT}!image/gif
RewriteCond %{HTTP_ACCEPT} text/html\s*;\s*q=0\.?0*(\s¦,¦$) [OR]
RewriteCond %{HTTP_ACCEPT}!text/html
RewriteCond %{HTTP_ACCEPT} (application¦\*)/(xhtml\+xml¦\*)
RewriteCond %{HTTP_ACCEPT}!application/xhtml\+xml\s*;\s*q=0\.?0*(\s¦,¦$)
RewriteCond %{REQUEST_URI} ^([^.]*¦.*\.html)$
RewriteRule .* - [T=application/xhtml+xml;charset=utf-8]
#
<Files comments.html>
AddType application/xhtml+xml .html
</Files>

# start with the assumption that everything is xhtml
AddType application/xhtml+xml html
RewriteRule ^([^.]*¦.*\.html)$ - [T=application/xhtml+xml;charset=utf-8]

# respect requests to not send xhtml
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml\s*;\s*q=0\.?0*(\s¦,¦$)
RewriteRule ^([^.]*¦.*\.html)$ - [T=text/html;charset=utf-8]

# standards based backwards compatibility - for tools like Lynx
RewriteCond %{HTTP_ACCEPT} text/html
RewriteCond %{HTTP_ACCEPT}!text/html\s*;\s*q=0\.?0*(\s¦,¦$)
RewriteCond %{HTTP_ACCEPT}!(application¦\*)/(xhtml\+xml¦\*)
RewriteRule ^([^.]*¦.*\.html)$ - [T=text/html;charset=utf-8]

# MSIE accomodation: simple click
RewriteCond %{HTTP_ACCEPT} image/gif
RewriteCond %{HTTP_ACCEPT}!html
RewriteRule ^([^.]*¦.*\.html)$ - [T=text/html;charset=utf-8]

# MSIE accomodation: open in new tab/window
RewriteCond %{HTTP_ACCEPT} ^\*/\*$
RewriteCond %{HTTP_USER_AGENT} MSIE
RewriteRule ^([^.]*¦.*\.html)$ - [T=text/html;charset=utf-8]

RewriteRule /([0-9]+¦index¦comments).(txt¦cdf¦ffkar¦rdf¦rss2?1?¦opml¦esf¦sn2¦xss) - [G,L]
RewriteRule ^([0-9]+¦index¦comments).(txt¦cdf¦ffkar¦rdf¦rss2?1?¦opml¦esf¦sn2¦xss)$ - [G,L]

[edited by: Markus_Klaffke at 10:32 pm (utc) on Oct. 28, 2007]