Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: htaccess - folders and categories of the same name  (Read 3991 times)

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
htaccess - folders and categories of the same name
« on: December 01, 2006, 02:16:28 pm »

for bram (and other apache guru's)

While testing RC3 I ran into the following.

Situation:
I have a sNews installation in its own folder on my local webserver (Mandrakelinux 10.1  / Apache 2.0).
I have, among others, a sub-folder called 'css' where I put my stylesheets (obviously)

Then I create a category in sNews called 'css' and I post an article in this category.
Now, when I point my browser to the category I get a 403 error
When I point my browser to the article, everything is fine, the article is displayed as it should.
However, when I create a sub-folder in the folder 'css' and I call it 'articlename', I get the same 403 error when I point to the article.

Another thing is that when you put an index.html (e.g. to prevent directory browsing) in the folder involved, that file will be displayed when you point your browser to that particularly category/folder.

So, I think we have a url rewriting issue on our hands here.

Look at the following line in the .htaccess-file:
RewriteCond %{REQUEST_FILENAME} !-d

I'm not a Apache expert, on the contrary, but I think this means:
  when the requested filename is not a directory
     then do the rewriting.
     
As i've seen this condition before in other CM-systems(with SEF-url's)  (and 1.4) it defenitly has an (important) function, but I don't quite see it; what happens if we this line out leave it out? When I tested this nothing went wrong. Can anyone explain the purpose of this condition to me?

And, more important, can this be fixed? Or does this mean that I can't have a category CSS or PHP or Photo's when I have a folder of the same name.
Logged
Confidence is reduced complexity.
brauck.nl for free css templates

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
htaccess - folders and categories of the same name
« Reply #1 on: December 01, 2006, 03:15:03 pm »

Interesting. I experienced the exact problem when I started using the RC2 and, for the time being, I just stayed away from using duplicate folder and article names. I thought it might be something I was doing wrong and decided to leave it till the stable version came out. What you have determined makes sense. Surely it will be repairable. If not, I would see this as a serious inconvenience.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
htaccess - folders and categories of the same name
« Reply #2 on: December 01, 2006, 04:40:33 pm »

Hi Brauck!
Yes! This is a _big_ problem... I'm not really sure if this work correctly at all...Try with this .htaccess file:
Quote

    php_value session.use_trans_sid 0

RewriteEngine On
RewriteBase /snews15
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ index.php?category=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?category=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+) index.php?category=$1&title=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+)/([^/]+)/ index.php?category=$1&title=$2&commentspage=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_-]+)/([0-9]+)/ index.php?category=$1 articlespage=$2 [L]
I've repeat the
Quote
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?category=$1 [L]
but removing, in this case, the " ! " sign.
I've tested with the same scenario like you and I found no problems (css folder, css category...)
I'm not really sure if this is a _really_ fix... I need to full test into my demo site... Please, try it into your site and
tell what happens.
Thanks,
bram.
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Espaņol

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
htaccess - folders and categories of the same name
« Reply #3 on: December 01, 2006, 05:26:07 pm »

Yo bram, I knew I could rely on you. Thanks mate, I'm going to try it out and let you know; however that will not before next Tuesday (busy, busy, busy  :) )
By the way, can you explain why this condition has to be there?
Logged
Confidence is reduced complexity.
brauck.nl for free css templates

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
htaccess - folders and categories of the same name
« Reply #4 on: December 01, 2006, 05:43:55 pm »

Ofcourse mate!
Repeating this condition:
Quote
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ index.php?category=$1 [L]
without the exclamation " ! " sign you _force_  Apache to rewriting all the real directories to as a part of your url but not their contents... In your case, now, if you point to your-site.com/css/article/ you get the article correctly and if you point to your-site.com/css/ you get the category 'css'. And, too, if you point to your-site.com/css/style.css you can view your style.css file without problem.
Thanks,
bram.

Pd:  If you want more info, please, read this Apache official doc about mod_rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Espaņol

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
htaccess - folders and categories of the same name
« Reply #5 on: December 01, 2006, 05:55:26 pm »

Thanks bram, you're the Man :D
Logged
Confidence is reduced complexity.
brauck.nl for free css templates

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
htaccess - folders and categories of the same name
« Reply #6 on: December 01, 2006, 06:37:07 pm »

Only one thing about this fix...  
If you need, for example, to access to your phmyadmin like your-site.com/snews15/phpmyadmin/
will be needed, too, to provide their index file 'index.php'  
I don't know how to solve this and/or if it's possible... but I think that this is not a big problem...  
Thanks,  
bram.
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Espaņol

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
htaccess - folders and categories of the same name
« Reply #7 on: December 01, 2006, 06:46:52 pm »

afaik, phpmyadmin has a different link defined by the hosting company, via cpanel or similar admin panel and not through the site itself; you're probably right - this shouldn't be a problem
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
htaccess - folders and categories of the same name
« Reply #8 on: December 01, 2006, 07:06:53 pm »

Yes Mika, but only are an a (bad) example... Another example, a photogallery or other app inside snews root folder...
Thanks,
bram.
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Espaņol

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
htaccess - folders and categories of the same name
« Reply #9 on: December 01, 2006, 11:03:49 pm »

OK bram, I see the picture. I try this out as well.
Logged
Confidence is reduced complexity.
brauck.nl for free css templates

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
htaccess - folders and categories of the same name
« Reply #10 on: December 03, 2006, 03:07:33 pm »

I did a test with the last .htaccess file (including RewriteCond %{REQUEST_FILENAME} -d etc.)
Everything works fine now.

Quote from: bram
Only one thing about this fix...
If you need, for example, to access to your phmyadmin like your-site.com/snews15/phpmyadmin/
will be needed, too, to provide their index file 'index.php'
I don't know how to solve this and/or if it's possible... but I think that this is not a big problem...
Thanks,
bram.
This stands, but as bram said, it's not a big problem.

Thanks guys for your help ;)
Logged
Confidence is reduced complexity.
brauck.nl for free css templates