mod_rewrite htaccess habilitar apache .htaccess redirect apache2

apache - htaccess - Eliminar barra inclinada después del dominio



mod_rewrite php (1)

Este es mi archivo .htaccess :

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Remove multiple slashes anywhere in URL RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ RewriteRule . %1/%2 [R=301,L] # Never use www prefix! RewriteCond %{HTTP_HOST} ^www.domain/.org [NC] RewriteRule (.*) http://domain.org/$1 [R=301,L] # Remove multiple slashes after domain RewriteRule ^/(.*)$ http://domain.org/$1 [R=301,L] # Remove trailing slash in some cases RewriteRule ^(.*)/.css/$ http://domain.org/$1.css [L,R=301] RewriteRule ^(.*)/.js/$ http://domain.org/$1.js [L,R=301] RewriteRule ^(.*)/.jpg/$ http://domain.org/$1.jpg [L,R=301] RewriteRule ^(.*)/.jpeg/$ http://domain.org/$1.jpeg [L,R=301] RewriteRule ^(.*)/.png/$ http://domain.org/$1.png [L,R=301] RewriteRule ^(.*)/.gif/$ http://domain.org/$1.gif [L,R=301] RewriteRule ^(.*)/.xml/$ http://domain.org/$1.xml [L,R=301] # Force trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !index.php RewriteCond %{REQUEST_URI} !(.*)/.css RewriteCond %{REQUEST_URI} !(.*)/.js RewriteCond %{REQUEST_URI} !(.*)/.jpg RewriteCond %{REQUEST_URI} !(.*)/.jpeg RewriteCond %{REQUEST_URI} !(.*)/.png RewriteCond %{REQUEST_URI} !(.*)/.gif RewriteCond %{REQUEST_URI} !(.*)/.xml RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://mydomain.org/$1/ [L,R=301] #Removes access to the system folder by users. #Additionally this will allow you to create a System.php controller, #previously this would not have been possible. #''system'' can be replaced if you have renamed your system folder. RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/$1 [L] #Checks to see if the user is attempting to access a valid file, #such as an image or css document, if this isn''t true it sends the #request to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] # MIME types AddType text/css .css AddType text/javascript .js # Enable compression AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript text/x-css text/x-javascript text/x-js text/htm application/x-javascript application/javascript application/js application/x-js image/png image/gif image/jpg image/jpeg #Skip browsers with known problems BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4/.0[678] no-gzip BrowserMatch /bMSIE !no-gzip !gzip-only-text/html php_flag display_errors on </IfModule> <IfModule !mod_rewrite.c> ErrorDocument 404 /index.php </IfModule>

Pero, cuando vaya a **///// , las barras posteriores no desaparecerán. ¿Qué estoy haciendo mal?


La variable% {REQUEST_URI} se reduce de barras adicionales cuando se prepara. Por lo tanto, la condición RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ Nunca coincidirá porque para una solicitud como http://domain.org//// , la variable REQUEST_URI se reduce a solo / . Intenta usar la variable THE_REQUEST:

RewriteCond %{THE_REQUEST} ^([A-Z]{3,9})/ (.*)//([^/ ]*) RewriteRule ^ %2/%3 [R=301,L]

Además, el prefijo (la barra diagonal) se elimina del URI de solicitud cuando las reglas de reescritura están en un archivo htaccess, por lo que la regla RewriteRule . %1/%2 [R=301,L] RewriteRule . %1/%2 [R=301,L] nunca coincidiría porque la expresión regular . requiere al menos un personaje para que coincida. Cuando el URI es / y la barra diagonal inicial se elimina, el URI que se utiliza para coincidir en la url es una cadena en blanco. Entonces, usando ^ , o (. *) , O algo equivalente a "todo, incluso nada", debe usarse regex.