2017-01-01 82 views
1

我已經制定了一些規則,例如重定向匹配,以動態指向舊網址到新的位置,但是任何時候我都會在URL編碼字符中出現重定向錯誤,根本不工作。 下面是這些URL的一個示例:網址編碼字符不會重新編寫的問題

www.example.com/ebc-drama-yebet-sira/yebet-sira-%E1%8B%A8%E1%89%A4%E1%89%B5-%E1%88%B5%E1%88%AB-drama-part-1-video_80c33bc56.html 

所以我需要刪除像字符: %E1%8B%A8%E1%89%A4%E1%89%B5-%E1%88% B5%E1%88%AB
以上這些字符是等於這個詞阿姆哈拉語:የቤት-ስራ
我需要的是一個規則,從URL中刪除非字母字符-numerical但保留所有的特殊字符,如「 - 「」_「等只是URL編碼字符。
我曾嘗試:

RewriteRule ^/?(.*)>$ /$1 [L,R=301] 

和:

RewriteRule (.*)[^a-zA-Z0-9](.*) $1$2 [N] 

的.htaccess文件:

Options -MultiViews 
RewriteEngine On 
RewriteRule ^index.html$ index.php 
RewriteRule ^browse.html$ category.php 
RewriteRule ^browse-(.*)-videos.html$ category.php?cat=$1 
RewriteRule ^browse-(.*)-videos-([0-9]+)-(.*).html$ category.php?cat=$1&page=$2&sortby=$3 
RewriteRule ^videos.flv(.*)$ videos.php$1 
RewriteRule ^videos.mp4(.*)$ videos.php$1 
RewriteRule ^register.html$ register.php 
RewriteRule ^contact_us.html$ contact_us.php 
RewriteRule ^edit_profile.html$ edit_profile.php 
RewriteRule ^suggest.html$ suggest.php 
RewriteRule ^upload.html$ upload.php 
RewriteRule ^upload_avatar.html$ upload_avatar.php 
RewriteRule ^suggest.html$ suggest.php 
RewriteRule ^favorites.html(.*)$ favorites.php$1 
RewriteRule ^login.html(.*)$ login.php$1 
RewriteRule ^newvideos.html(.*)$ newvideos.php$1 
RewriteRule ^topvideos.html(.*)$ topvideos.php$1 
RewriteRule ^profile.html(.*)$ profile.php$1 
RewriteRule ^user/([^/]+)/?$ user.php?u=$1 
RewriteRule ^user/([^/]+)/(.*)/?$ user.php?u=$1&view=$2 
RewriteRule ^memberlist.html(.*)$ memberlist.php$1 
RewriteRule ^playlists.html(.*)$ playlists.php$1 
RewriteRule ^index-([0-9]+).html$ article.php?page=$1 
RewriteRule ^browse-(.*)-([0-9]+).html$ article.php?c=$1&page=$2 
RewriteRule ^articles/tag/([^/]+)/page-([0-9]+)(/)?$ article.php?tag=$1&page=$2 
RewriteRule ^articles/tag/([^/]+)(/)?$ article.php?tag=$1&page=1 
RewriteRule ^popular-([0-9]+).html$ article.php?show=popular&page=$1 
RewriteRule ^(.*)_([0-9]+).html$ article_read.php?a=$2 
RewriteRule ^articles(\/|.html)?$ article.php 
RewriteRule ^article(\/|.html)?$ article.php 
RewriteRule ^pages/(.*)\.html$ page.php?name=$1 
RewriteRule ^playlist/(.*)/([^/]+)(/)?$ watch.php?playlist=$1&vid=$2 
RewriteRule ^playlist/(.*)$ playlists.php?playlist=$1 
RewriteRule ^tags/([^/]+)/$ tag.php?t=$1&page=1 
RewriteRule ^tags/([^/]+)/page-([0-9]+)(/)?$ tag.php?t=$1&page=$2 
RewriteRule ^embed/([^/]+)$ embed.php?vid=$1 
RewriteRule ^([^/]*)_([a-zA-Z0-9]{9}).html$ watch.php?vid=$2 
RewriteRule ^fpembed-(.*).swf$ fpembed.php?vid=$1 
RewriteRule ^uploads/thumbs/(.*)-social.(jpg|gif|png)$ social-thumb.php?vid=$1 
RewriteRule ^rss.xml$ rss.php [L] 
RedirectMatch 301 ^/[\w-]+/([\w-]+\.html)$ /$1 

感謝。

回答

0

您可以在網站根目錄的.htaccess使用這些規則:

RewriteEngine On 

# skip all css/js/images from rewrite rules below 
RewriteRule \.(?:jpe?g|gif|bmp|png|ico|tiff|css|js)$ - [L,NC] 

RewriteCond %{REQUEST_URI} !^/(admin|articles?|user|tags|embed|playlist|uploads)(/.*)?$ [NC] 
RewriteRule ^(.*)[^\w/.-]+(.*\.html)$ $1$2 [DPI,N,E=SP:1] 

RewriteCond %{ENV:SP} =1 
RewriteRule ^[\w.-]*$ /$0 [L,R=302,NE] 

# comment out RedirectMatch 301 rule 

# remaining RewriteRule appear here 

這將重定向到/ebc-drama-yebet-sira/yebet-sira-%E1%8B%A8%E1%89%A4%E1%89%B5-%E1%88%B5%E1%88%AB-drama-part-1-video_80c33bc56.html/ebc-drama-yebet-sirayebet-sira---drama-part-1-video_80c33bc56.html刪除所有特殊字符。

+0

對不起,延誤@anubhava,實際上這個代碼導致css崩潰或網站加載像無限..我必須注意到,正在使用您給我的另一個規則,即:'RedirectMatch 301 ^/[\ w - ] + /([\ w - ] + \。html)$/$ 1'這個老規則也提出了另一個問題,使得其他htaccess文件在其他域中無法正常工作(刪除它將修復,但它在主域中正常工作,規則是重要) –

+0

完成後,請查看更新後的問題。 –

+0

評論出'RedirectMatch 301'規則,並將我的給定規則放在'RewriteEngine On'行的下方 – anubhava

0

嘗試

[^a-zA-Z0-9-_./] 

,你可以在這裏測試您的規則 http://www.regextester.com/

+0

http://martinmelin.se/rewrite-rule-tester/ –

+0

如果我加%,那麼url會保留%chars並永遠不會重定向。 http://martinmelin.se/rewrite-rule-tester/ –

+0

你是對的...我編輯我的答案上面..這將刪除所有%,但保持 - 和_還/ – Tina