簡體   English   中英

使用htaccess刪除網址中的空格或%20

[英]Removing whitespaces or %20 in url using htaccess

嗨,大家好,我可以在這里遇到一些麻煩,以便使用htaccess刪除我網址中的所有20%並用連字符替換。我設法擺脫了Acer,Liquid,S1一詞之間的其他20% ,S510

這是我的網址/ localhost / gadgets / product / Acer-Liquid-S1-S510%20Mobile

如您所見,最后一部分有一個%20,我該如何刪除它

這是我的htaccess

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /gadgets/

Options -Indexes

RewriteRule ^brand/([a-zA-Z]+)$ brand.php?id=$1

RewriteRule ^product/([A-Za-z0-9-]+)/?$   product.php?product_name=$1-$2 [NC,L]

RewriteRule ^(.*/|)[\s%20]+(.+)$ $1$2 [L]

RewriteRule ^(.+?)[\s%20]+(/.*|)$ $1$2 [L]

RewriteRule ^([^\s%20]*)(?:\s|%20)+(.*)$ $1-$2 [L,R]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^(.*)$ $1.php

在此先感謝大家

嘗試這個:

Options +FollowSymLinks -MultiViews -Indexes

RewriteEngine On
RewriteBase /gadgets/

RewriteRule ^([^\s%20]*)(?:\s|%20)+(.*)$ $1-$2 [N,E=Redirect:1]

RewriteCond {ENV:Redirect} ^1$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R,L]

RewriteRule ^brand/([a-zA-Z]+)$ brand.php?id=$1 [NC,L]
RewriteRule ^product/([A-Za-z0-9-]+)/?$ product.php?product_name=$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

第一條規則刪除循環中的所有空格(使用[N] ),因此我們現在不必指定多個RewriteRules一次一個地進行操作。

下一條規則(帶有{ENV:Redirect}條件)是可選的,並且用於反映客戶端瀏覽器上連字符的使用,以便創建的所有書簽都鏈接到URL的正確非空白版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM