问题描述
|
我的.htaccess重写传奇的另一个版本。现在一切都在一定程度上起作用,但是仍然存在一些问题。
我有很多规则将旧的url移到新的url,传递变量等-但是,我仍然需要添加一些内容,而对于我的生活来说,这是无法解决的。
我有3个如下所示的网址以进行重定向。
1 www.mydomain.com/news/dentistry_dental/index.PHP
2 www.mydomain.com/news/dentistry_dental/index.PHP?month=April&year=2011
3 www.mydomain.com/news/dentistry_dental/article_detail.PHP?article=1234&title=some-title
将它们分别重定向并完美地重写到新的URL
1 www.mydomain.com/dental_news/
2 www.mydomain.com/dental_news/2011年4月
3 www.mydomain.com/dental_news/1234-some-title
但是...这是问题#1以下网址也正在重定向,如下所示
4 www.mydomain.com/news/it_technology/index.PHP?month=April&year=2011
5 www.mydomain.com/news/it_technology/article_detail.PHP?article=1234&title=some-title
也指向与牙科重定向相同的网址
4 www.mydomain.com/dental_news/2011年4月
5 www.mydomain.com/dental_news/1234-some-title
哪个不应该发生。 it_technology新闻文章现在已被删除,因此我希望使用410或类似名称将它们重定向到我的主页,以最佳选择为准。
我当前的.htaccess如下所示。
选项+关注符号链接
在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中的最后一条规则已将其删除。
我尝试了许多通过google找到的方法,但是所有方法都与我的其他规则一起引发了问题。
希望有人可以帮助我一劳永逸地完成此任务。
问候
中号
解决方法
当然会变得复杂:)尝试更改这些行(我认为有2条):
RewriteCond %{REQUEST_URI} !^/dental_news/
至:
RewriteCond %{REQUEST_URI} ^/news/dentistry_dental/
这样一来,它只会将旧的牙科新闻URL重定向到相应的新URL。
,琐碎地讲,您的问题就是所有规则:
#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]
将它们限制为您要重写的路径,即用更具体的内容替换“ 4”,例如:
#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 ^news/dentistry_dental/index.php$ /dental_news/%1-%2? [L,R=301]
RewriteCond %{REQUEST_URI} !^/dental_news/
RewriteCond %{QUERY_STRING} month=([^&]*)&year=([^&]*)$
RewriteRule ^news/dentistry_dental/index.php$ /dental_news/%1-%2? [R=301]
您可以将“ 6”重定向作为标准重定向。
RewriteRule ^news/it_technology http://www.thepage.com/ [R=301,L]
从技术上讲,使用410可能更正确,但是410代码实际上是可选的。您可能还希望将其设置为404,然后从404页面到主页具有链接。