MOD重定向和重写(第二部分) [英] mod redirect and rewrites ( Part 2 )
问题描述
继我previous问题,我得到我的自成一团糟,所以我会尝试,奠定了我的问题/ s的出来是最好的,我可以在这里。
Further to my previous questions i am getting my self into a mess, so i will try and lay my problem/s out as best as i can here.
我整理我的网址结构,但有我的网址在搜索引擎以及索引的问题,所以我需要重写我的网址,同时重定向他们。
I am tidying up my URL structure but have the problem that my urls are well indexed in Search engines, so i need to rewrite my urls while also redirect them.
通过先前在previous的问题,我目前在我的.htaccess以下帮助
With help earlier on a previous question i currently have the following in my .htaccess
Options +FollowSymlinks
RewriteEngine on
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 %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.mydomain.com/$1 [R=301]
# Rewrite A newly added section rewrite ( no redirect required )
RewriteRule ^products/digital_imaging/([^/]*)/([^/]*)$ /products/digital_xray.php?id=$1&product=$2 [L]
# Rewrite dental news article to neat nice url
RewriteRule ^dental_news/([^/]*)/([^/]*)$ news/dentistry_dental/article_detail.php?article=$1&title=$2&redirect [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]
所以,这是所有工作正常,但我有另外一个网址,在这并不一定是有PHP变量的index.php结束,这个我还需要通过努力做自己我重写和重定向,创建的某些种类的冲突,它并不如预期的工作。
So, this is all working as expected, but i have another url that ends in a index.php that sometimes but not always has php variables, this i also need to rewrite and redirect, by trying to do it myself i am creating a conflict of some sorts, and its not working as expected.
该网址我需要重写&安培;用301重定向低于
The URL i need to rewrite & redirect with a 301 is below
http://www.mydomain.com/news/dentistry_dental/index.php?month=February&year=2011
With the previous index.php rule it currently displays as
http://www.mydomain.com/news/dentistry_dental/?month=February&year=2011
Half way there i guess... I need it to be the following
http://www.mydomain.com/dental_news/February/2011
霸菱记住该URL有时没有变量如下
Baring in mind that the url sometimes has no variables as below
http://www.mydomain.com/news/dentistry_dental/index.php
Which is currently with the index.php rule above is showing as
http://www.mydomain.com/news/dentistry_dental/
This needs to be
http://www.mydomain.com/dental_news/
所以,是的,我完全扯淡这个东西,它是完全新的给我,所以如果我能得到这个排序生病是一件很快乐的兔子哉!
So yes, i am totally crap at this stuff, it is entirely new to me, so if i can get this sorted ill be a very happy bunny indeed!
感谢所有
修改
好吧我目前的.htaccess看起来如下图所示。
Ok my current .htaccess looks as below.
Options +FollowSymlinks
RewriteEngine on
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 %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.mydomain.com/$1 [R=301]
RewriteRule ^products/digital_imaging/([^/]*)/([^/]*)$ /products/digital_xray.php?id=$1&product=$2 [L]
# Rewrite dental news article to neat nice url
RewriteRule ^dental_news/([^/]*)/([^/]*)$ news/dentistry_dental/article_detail.php?article=$1&title=$2&redirect [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 %{QUERY_STRING} month=([^&]*)&year=([^&]*)
RewriteRule (.*) /dental_news/%1/%2? [R=301]
RewriteRule news/dentistry_dental/$ /dental_news/ [R=301]
RewriteRule ^dental_news/$ /news/dentistry_dental/index.php [L]
因为它的立场与此,出现以下情况
As it stands with this, The following occurs
www.mydomain.com/news/dentistry_dental/index.php
-> www.mydomain.com/dental_news/
(^正确的)
www.mydomain.com/news/dentistry_dental/index.php?month=May&year=2011
-> www.mydomain.com/dental_news/April/2011
(^错误:在显示地址栏正确的道路,但与变量显示article_detail.php代替的index.php)
( ^ Wrong : Showing right path in url bar, but displaying article_detail.php instead of index.php with variables)
我猜测的规则2是相似的,一个是捡了年和月变量的index.php和发送到article_detail页面。我可能是错的但是我不知道如何解决。
I am guessing that 2 of the rules are similar and one is picking up the index.php with year and month variables and sending to article_detail page. I might be wrong however and i have no idea how to fix.
编辑#2
目前的.htaccess如下图所示。
Current .htaccess as below.
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^dentalsupportuk.com [nc]
rewriterule ^(.*)$ http://www.dentalsupportuk.com/$1 [r=301,nc]
# Rewrite all index.php to root: / ( with perm redirect )
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.dentalsupportuk.com/$1 [R=301]
RewriteRule ^products/digital_imaging/([^/]*)/([^/]*)$ /products/digital_xray.php?id=$1&product=$2 [L]
# Rewrite dental news article to neat nice url
RewriteRule ^dental_news/([0-9]*)/([^/]*)$ news/dentistry_dental/article_detail.php?article=$1&title=$2&redirect [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 %{QUERY_STRING} month=([^&]*)&year=([^&]*)
RewriteRule (.*) /dental_news/%1/%2? [R=301]
RewriteRule news/dentistry_dental/$ /dental_news/ [R=301]
RewriteRule ^dental_news/([a-zA-Z]*)/([0-9]*)$ news/dentistry_dental/index.php?month=$1&year=$2&redirect [L]
www.mydomain.com/dental_news/现在的重写以www.mydomain.com/dental_news/~~V哪些犯规存在,因此404错误(应该重写www.mydomain.com/news/dentistry_dental~~V /)
www.mydomain.com/dental_news/ is now rewriting to www.mydomain.com/dental_news/ which doesnt exist so 404 error ( should be rewriting to www.mydomain.com/news/dentistry_dental/ )
www.mydomain.com/dental_news/100/some-title现在的重写如预期的变量(工作),以www.mydomain.com/news/dentistry_dental/article_detail.php~~V
www.mydomain.com/dental_news/100/some-title is now rewriting as expected to www.mydomain.com/news/dentistry_dental/article_detail.php with the variables ( working )
www.mydomain.com/news/dentistry_dental/article_detail.php?article=100&title=some-title是的重定向如预期的那样www.mydomain.com/dental_news/100/some-~~V标题和正常显示(工作)
www.mydomain.com/news/dentistry_dental/article_detail.php?article=100&title=some-title is redirecting as expected to www.mydomain.com/dental_news/100/some-title and displaying correctly ( working )
www.mydomain.com/news/dentistry_dental/index.php?month=May&year=2010是的重定向,但撞车出局,说明火狐(Firefox已经检测到服务器重定向的请求这个地址的方式,将永远不会完成。)(不工作,这是某种循环造成的?)
www.mydomain.com/news/dentistry_dental/index.php?month=May&year=2010 is redirecting but crashing out Firefox stating ( Firefox has detected that the server is redirecting the request for this address in a way that will never complete. ) ( Not Working, is this some sort of loop causing this? )
www.mydomain.com/dental_news/July/2010/在重写是给我一个404错误。
www.mydomain.com/dental_news/July/2010/ the rewriting is giving me a 404 error.
所以,是的,即时得到处都是,也许香港专业教育学院放顺序错误或东西,但我越乱越IM吓得打破一切。任何想法?
So yes, im all over the place, maybe ive put in wrong order or something, but the more i mess the more im scared of breaking everything. Any ideas?
问候
中号
推荐答案
尝试添加遵循两个规则:
Try adding the follow two rules:
RewriteCond %{QUERY_STRING} month=([^&]*)&year=([^&]*)
RewriteRule (.*) /dental_news/%1/%2? [R=301]
RewriteRule news/dentistry_dental/$ /dental_news/ [R=301]
我不相信它会导致任何冲突,似乎涵盖您所描述的两个场景。
I don't believe it causes any conflicts, and seems to cover the two scenarios you described.
修改
OK,所以如果我得到这个正确的,这是网址 / dental_news / 2968 /重新定义,口腔卫生干预
应该重写 /news/dentistry_dental/article_detail.php
通过适当的查询字符串。然后 / dental_news /月/ 2011
应该重写 /news/dentistry_dental/index.php
。所以......如果是这样的话,你应该可以添加以下规则:
OK, so if I'm getting this correct, the URLs that are /dental_news/2968/Redefining-oral-hygiene-intervention
should be rewritten to /news/dentistry_dental/article_detail.php
with the proper querystrings. And then the /dental_news/April/2011
should be rewritten to /news/dentistry_dental/index.php
. So...if that is the case, you should be able to add the following rule:
RewriteRule ^dental_news/([a-zA-Z]*)/([0-9]*)$ news/dentistry_dental/index.php?month=$1&year=$2&redirect [L]
这也很可能是有意义的做如下更新:
It would also probably make sense to make the following update:
电流:<?code>重写规则^ dental_news /([^ /] *)/([^ /] *)$新闻/ dentistry_dental / article_detail.php文章= $ 1安培;标题= $ 2及重定向[L]
更新:重写规则^ dental_news /([0-9] *)/([^ /] *)$ 1新闻/ dentistry_dental / article_detail.php文章= $&安培;标题= $ 2及?重定向[L]
的区别有是它是更具体的,第一组的正则表达式将只匹配一组数字,将有助于避免你的规则正在改写到的index.php <冲突/ code>文件。
The difference there being that it is more specific, and the first regex group will only match a group of digits, and will help to avoid conflict with your rule that is rewriting to the index.php
file.
编辑2
我相信我测试了所有您所提供的网址,他们似乎是现在的工作。有一对夫妇重定向循环,我们是不占。希望这将有助于...
EDIT 2 I believe I tested all of the URLs you provided, and they seem to be working now. There were a couple of redirect loops that we weren't accounting for. Hopefully this will help...
Options +FollowSymlinks
RewriteEngine on
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 %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.mydomain.com/$1 [R=301]
RewriteRule ^products/digital_imaging/([^/]*)/([^/]*)$ /products/digital_xray.php?id=$1&product=$2 [L]
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]
希望这有助于。
这篇关于MOD重定向和重写(第二部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!