Apache mod reescritura, DirectorySlash Off root fix (ver índice de)

I'm very unfortunately stuck here. I did a htaccess redirect for clean url. But whenever I had a path that corresponded to an existing directory, a backslash would be added which was very annoying and produced error in my script.

So I changed the DirectorySlash option to Off and it beautifully fixed my problem. Yes I am aware of the security warning and de-activated indexes.

Now my big problem is as follow: I cannot redirect to my index.php if the path to the website is entered WITHOUT the trailing slash because the REQUEST_URI is empty.

so,"www.my-website.com/" will work but "www.my-website.com" will not.

I thought to myself "well I'll just detect if the REQUEST is empty". nothing happens. Or mayble turn off directoryslash for subfolders only? After hours of searching, I found that the following did work but meant I had to write the url in hard and that really not optimal

Options +FollowSymlinks
RewriteEngine on
  #prevent from weird bug if path is a directory
DirectorySlash Off

  # add the trailing slash to root directory
  # THIS IS WHERE I NEED A VARIABLE PATH THAT I DON'T NEED TO CHANGE MANUALY
RedirectMatch ^/?([^\.\/]+)$ http://my-fixed-url.com/$1/

  # Don't show directory indexes (the listing of files)
Options -Indexes -MultiViews

  # as long is it isn't an existing file
RewriteCond %{REQUEST_FILENAME} !-f

  # Then redirect to index.php with the param "path" set to the url
RewriteRule ^([a-zA-Z0-9\_\-\/\.]+)$ index.php?path=$1 [QSA]

¡Cualquier ayuda es muy apreciada!

preguntado el 28 de agosto de 12 a las 13:08

1 Respuestas

Solo cambia el + a una *, to also match this 'empty' url. So:

RewriteRule ^([a-zA-Z0-9\_\-\/\.]*)$ index.php?path=$1 [QSA]

Respondido 28 ago 12, 22:08

try just adding this rule at the end: RewriteRule ^$ index.php?path=/ - Gerben

no, absolutely nothing. Just as a reminder, DirectorySlash if Off - rwt

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.