我的.htaccess重寫傳奇的另一個版本。一切現在都在努力,但仍然有一些問題。htaccess重寫仍然有些問題,變得有點複雜!
我有很多規則來移動舊網址到新的URL,傳遞變量等 - 但仍然有一些事情,我需要補充,併爲我的生活無法弄清楚。
我有3個網站正在指導/重寫如下。
1 www.mydomain.com/news/dentistry_dental/index.php
2 www.mydomain.com/news/dentistry_dental/index.php?month=April &年= 2011
3 www.mydomain.com/news/dentistry_dental/article_detail.php?article=1234 &標題=一些標題
這些被重定向&完美改寫爲新網址分別
1 www.mydomain.com/dental_news/
2 www.mydomain.com/dental_news/April-2011
3 www.mydomain.com/dental_news/1234-一些標題
但是......這裏的問題是#1以下URL也重定向如下
4 www.mydomain.com/news/it_technology/index.php?month=April &年= 2011
5 www.mydomain.com/news/it_technology/article_detail.php?article= 1234 &標題=一些標題
哪還引導到相同的網址作爲牙科重定向
4 www.mydomain.com/dental_news/April-2011
5 www.mydomain.com/dental_news/1234-some-title
這不應該發生。 it_technology新聞文章現在已被刪除,所以我希望將它們重定向到410或類似的主頁,無論哪個都是最好的選擇。
我目前的.htaccess看起來如下。
選項+的FollowSymLinks RewriteEngine敘述 上
rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc]
# Rewrite all index.php to root:/(with perm redirect)
RewriteCond %{REQUEST_URI} !/generator/
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.mydomain.com/$1 [R=301]
RewriteRule ^products/dental-digital-imaging/([^/]*)_([^/]*)$ /products/digital_xray.php?id=$1&product=$2 [L]
RewriteRule ^products/package_deals.php$ http://www.mydomain.com/products/dental-computer-network-bundles [R=301]
RewriteRule ^products/computer_hardware.php$ http://www.mydomain.com/products/dental-computer-solutions [R=301]
RewriteRule ^products/individual_computers.php$ http://www.mydomain.com/products/dental-computer-systems [R=301]
RewriteRule ^products/digital_xray_imaging.php$ http://www.mydomain.com/products/dental-digital-imaging [R=301]
RewriteRule dental_news/$ /news/dentistry_dental/?rewrite [L]
# Rewrite dental news article to neat nice url
# Protect from looping because of previous rules
RewriteCond %{QUERY_STRING} !rewrite
RewriteRule ^dental_news/([0-9]*)-([^/]*)$ news/dentistry_dental/article_detail.php?article=$1&title=$2&rewrite [L]
#Conditional rewrite of old news article path to new one with 301 redirect
RewriteCond %{REQUEST_URI} !^/dental_news/
RewriteCond %{QUERY_STRING} article=([0-9]*)&title=([^&]*)$
RewriteRule (.*) /dental_news/%1-%2? [L,R=301]
RewriteCond %{REQUEST_URI} !^/dental_news/
RewriteCond %{QUERY_STRING} month=([^&]*)&year=([^&]*)$
RewriteRule (.*) /dental_news/%1-%2? [R=301]
# Protect from looping because of previous rules
RewriteCond %{QUERY_STRING} !rewrite
RewriteRule news/dentistry_dental/$ /dental_news/ [R=301]
# Protect from looping because of previous rules
RewriteCond %{QUERY_STRING} !rewrite
RewriteRule ^dental_news/([a-zA-Z]*)-([0-9]*)/?$ news/dentistry_dental/index.php?month=$1&year=$2&rewrite [L]
# Rewrite URL stripping .php Extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
我唯一的其他規定將尾隨斜線添加到文件服務的PHP(已添加媒體鏈接的php擴展,在我的最後一個規則刪除。 htaccess的。
我已經試過,我已經通過谷歌找到很多方法,但他們都cuase probelms與我的其他規則。
希望有人能幫助我完成這一關一勞永逸。
問候 中號
嗨clmarquart,再次感謝您的意見,我也會嘗試這個選項,並儘快報告,非常感謝您的幫助。 Regards M – madmatuk 2011-04-14 14:16:10
工作完美 - 我已經重定向了我的舊版新聞頁面,所以這就是所有排序,只有尾部斜線現在排序:) – madmatuk 2011-04-14 15:47:17