Forum Moderators: phranque

Message Too Old, No Replies

CMS specific rulesets .htaccess

Could this written differently?

         

mod confused

2:52 pm on Oct 19, 2007 (gmt 0)

10+ Year Member



Hi to all

I am posting this and registered to this forum to discuss, share and may be improve the following ruleset, which is .htaccess/public root directory specific for a custom CMS setup that renders multi-lingual content on symmetric URL structures.

The CMS, which is employed already uses mod_rewrite, and most URL's are taken care of from within the CMS.
( This is partly very specific. However, may be others will find this useful in other CMS circumstances )

I will try to explain first what I want the rules to do, and then post the whole .htaccess file content with an amendment of concern beneath:

- omit arbitrary suffix of index.php/index.html on all pages
- omit www prefix
- Requests to http://example.com/specialsection should return a 404, and are taken care of through a PHP include.Only requests to
http://example.com/specialsection/\d+ are supposed to return content. However, this breaks some default behavior of the CMS, since
content, which is available under http://example.com/specialsection/\d+ is also now available under http://example.com/specialsection/\d+/.* In order to fix this, I need the third rule ( # omit any artitrary subsection requests )
- The fourth rule is pretty specific. It fixes a problem with content, that is available at two different locations for the english default language. So we want to tell it to redirect any requests, that are not prefixed with the /en/ lang url part to the /en/ location.
- Fifth Rule: Omit the trailing slash for all requests, without disturbing the adminurl (cmsbackendurl)

- The rest of the rules are CMS specific, and should basically be left alone, in most circumstances.

<code>#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#RewriteBase /relative/web/path/

RewriteEngine On

RewriteBase /

# Omit suffix
RewriteCond %{THE_REQUEST} ^(GET¦HEAD)\ /([^/]+/)*index\.(php¦html)\ HTTP
RewriteRule ^(([^/]+/)*)index\.(php¦html)$ http://example.com/$1 [R=301,L]

# Omit prefix
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule (.*) http://example.com/$1 [R=301,L]

# Omit any arbitrary subsection requests. Requests for /specialsection/ are handled internally by the CMS to return a 404 response header. This rule aims, to fix the additional Issues that accour, redirectiong to the former mentioned location
RewriteCond %{REQUEST_URI} /(specialsection)/(\d+)/(/?.+)
RewriteRule /(specialsection)/(\d+)/(/?.+) http://example.com/en/specialsection [L,R=301]

# Prevent default language double indexing
# Redirect all requests not to /en/.* to /en/.*

RewriteCond %{REQUEST_URI}!/index\.php
RewriteRule ^(section1¦section2¦section3¦specialsection)(.+)?$ http://example.com/en/$1$2/ [L,R=301]

# Omit trailing slash, but leave the backend alone

RewriteCond %{REQUEST_URI}!(/index\.php¦cmsbackendurl)
RewriteRule ^(.*)/$ http://example.com/$1 [R=301,L]

# Default CMS Rules

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]

RewriteRule ^(.*) index.php

#php_value register_globals 0</code>

My concerns:

- Are those rules written effectively? Do they maybe use too much memory or CPU cycles?.
- Could the same thing may be achieved with less rules to be combined?
- Any mistakes, that I might have done in the syntax.

( Thanks also for the very usefull resources that are provided here on this forum, which I used some code from as well.)

regards and thanks in advance for any feedback

g1smd

3:07 pm on Oct 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Some of those rules form a redirection chain.

URL A is redirected to URL B is redirected to URL C.

That situation needs to be avoided wherever possible.

mod confused

5:29 pm on Oct 19, 2007 (gmt 0)

10+ Year Member



g1smd, thanks for your reply,

Could you give me any advice, which of those rules are good candidates, to be combined into one rule?

E.g.: omit trailing-slash with redirect suffix urls.

May be I can get it then at least to the point, where instead of:

A -> B -> C

to behave like:

A -> B

regards, mod_confused