mod_rewrite redirects the wrong way

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
marduk21

mod_rewrite redirects the wrong way

Post by marduk21 »

Hi!

I try to get CMSMS working with mod_rewrite enabled. Everything works fine, besides one thing. I have a page named sitemap and a file called sitemap.xml.gz. Now if I go to http://www.k-d-w.org/sitemap/  an error message is displayed and the apache log says:
File does not exist: /is/htdocs/wp1075967_82SQVOPJHD/www/sitemap.xml.gz
This behaviour is very weird to me and don't have any clue what could have gone wrong. Hopefully, someone here can help me with this.

I uploaded the following htaccess file:

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^([A-Za-z0-9-/]+)/?$ index.php?page=$1 [QSA]
Pierre M.

Re: mod_rewrite redirects the wrong way

Post by Pierre M. »

Hello marduk21,

By trying .org/sitemap/ I get your 404.
By trying .org/sitemap I get a 200 OK response :
Server: Apache/...
Content-Location: sitemap.xml.gz
Vary: negotiate
TCN: choice

...
Content-Type: text/xml
Content-Encoding: gzip

This means two things too me :
-your webserver has Transparent Content Negociation (TCN) enabled (and mod_deflate too). When /name is requested, it serves the /name.xml.gz flavor if available.
-your first rewrite rule (adding a trailing slash) is shadowed by TCN or you .htaccess is somewhat inactive.

Sorry to ask this, but does your .htaccess file have its dot prefix ? You write "htaccess" and not ".htaccess".

If your dot is OK, why not puting your whatever.xml.or.not files in /some/subfolder ?

BTW, why not use an URL scheme with ".html" page suffix ? Pages(.html) would not have names conflicting with uploaded files.

Pierre M.
marduk21

Re: mod_rewrite redirects the wrong way

Post by marduk21 »

Hi!

Thanks for your help! I changed the suffix to ".html" and the sitemap URL know works, too.
Nevertheless, the link to the RSS feed doesn't work now. Here's my new .htaccess:

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^([A-Za-z0-9-/]+)\.html$ index.php?page=$1 [QSA]
Pierre M.

Re: mod_rewrite redirects the wrong way

Post by Pierre M. »

Hello again,

if you like ".html" postfixed URLs, why do you still try to add trailing slashes ? I don't see your first rewriteconds and rewriterule in the manual or sample .htaccess.

This should be enough for the XML feed and pages.html :

Code: Select all

RewriteEngine On
RewriteBase /

#try to rewrite your specific news XML feed URL (/mynews.xml)
RewriteRule ^mynews\.xml$ index.php/news/rss [L]
#or may be [QSA] instead of [L] depending on how news categories are handled

#try the usual case
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
#it may require (uncomment it) this additional condition for news items to show :
#RewriteCond %{REQUEST_FILENAME} !^/news/(.+)$
RewriteRule ^(.+)\.html$ index.php?page=$1 [QSA]
Hope it works <;^)

Pierre M.
marduk21

Re: mod_rewrite redirects the wrong way

Post by marduk21 »

Your suggestion didn't work, but I found http://wiki.cmsmadesimple.org/index.php ... retty_URLs and changed my .htaccess to

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteRule ^News/rss(.+)$ index.php?page=News/rss$1 [S=1]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^([A-Za-z0-9-/]+)\.html$ index.php?page=$1 [QSA]
Now it works perfectly, thanks for your help.
Locked

Return to “CMSMS Core”