2012-01-05 34 views
5

Tôi có viết lại quy tắc sau:Remove trailing slash nếu không phải là một thư mục với apache

#remove the www. 
RewriteCond %{HTTP_HOST} ^www.website.co.uk$ [NC] 
RewriteRule ^(.*)$ http://local.website.co.uk/$1 [R=301,L] 

#this removes php extention 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

# stops you accessing url with.php 
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^.?\ ]+)\.php 
RewriteRule ^([^.]+)\.php(/.+)?$ /$1%{PATH_INFO} [R=301] 

tôi muốn thêm vào trong một quy tắc mà loại bỏ các dấu gạch chéo nếu ai đó cố gắng truy cập vào trang web với một.

ví dụ

website.co.uk/cheese/ nên chuyển hướng đến/pho mát

như bạn có thể thấy tôi có một quy tắc mà chuyển hướng ursl với gia hạn .php, không chắc chắn bắt đầu từ đâu.

Tôi có thư mục trong thư mục gốc mà tôi không muốn xóa url theo sau, nhưng tôi có thể thêm quy tắc bỏ qua cho các thư mục đó.

Cheers

Trả lời

13

Hãy thay đổi dưới đây vào file .htaccess

RewriteEngine on 
RewriteBase/

#existing rule 
#remove the www. 
RewriteCond %{HTTP_HOST} ^www.website.co.uk$ [NC] 
RewriteRule ^(.*)$ http://local.website.co.uk/$1 [R=301,L] 

#new Rule 
#if its not a directory 
RewriteCond %{REQUEST_FILENAME} !-d 
#and it has a trailing slash then redirect to URL without slash 
RewriteRule ^(.+)/$ /$1 [L,R=301] 

# rest of your existing rules go here 
+0

hoàn hảo cảm ơn! – AJFMEDIA

Các vấn đề liên quan