0

Hello I would like to remove any trailing slashes from my clean urls so far my htaccess has the following code:

#php_flag display_startup_errors on
#php_flag display_errors on
#php_flag html_errors on

RewriteEngine on

<IfModule mod_gzip.c>
    mod_gzip_on       Yes
    mod_gzip_dechunk  Yes
    mod_gzip_item_include file      \.(html?|txt|css|js|php|pl|jpg|png|gif)$
    mod_gzip_item_include handler   ^cgi-script$
    mod_gzip_item_include mime      ^text/.*
    mod_gzip_item_include mime      ^application/x-javascript.*
    mod_gzip_item_exclude mime      ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

Options -Indexes

RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)(.*)$ /index.php?page=$1&request=$2

#GAMW TON OHANAH
RedirectMatch 301 ^/component/(.*)$ http://www . evented . gr


ErrorDocument 404 /error.php?e=404
ErrorDocument 400 /error.php?e=400
ErrorDocument 401 /error.php?e=401
ErrorDocument 403 /error.php?e=403
ErrorDocument 405 /error.php?e=405
ErrorDocument 408 /error.php?e=408
ErrorDocument 410 /error.php?e=410
ErrorDocument 411 /error.php?e=411
ErrorDocument 412 /error.php?e=412
ErrorDocument 413 /error.php?e=413
ErrorDocument 414 /error.php?e=414
ErrorDocument 415 /error.php?e=415
ErrorDocument 500 /error.php?e=500
ErrorDocument 501 /error.php?e=501
ErrorDocument 502 /error.php?e=502
ErrorDocument 503 /error.php?e=503
ErrorDocument 506 /error.php?e=506

You may observe the strange behaviour if you like by visiting www . evented . gr

PS. I want consequtive slashes that have nothing in between to be replaced with 0 slash for example www.domain.com////// to www.domain.com or www.domain.com/events////// to www.domain.com/events

I have tryed the following but with no luck

RewriteCond %{REQUEST_URI} ^(.*?)(?:/){2,}$
RewriteRule . $1/ [R=301,L]

and

RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
4

1 回答 1

0

You can't do this with mod_rewrite. By the time your rules get applied, apache has already normalized the URI, all duplicate slashes are removed. If you make a request for:

http://www.evented.gr//////a////////b/////c/////d///////

The URI that mod_rewrite sees is this:

/a/b/c/d/

You'll have to come up with a different solution. The best thing to do is to fix this at the source, don't deploy with URLs that have duplicate slashes in the first place.

于 2012-12-27T07:08:16.377 回答