这究竟是什么重定向问题的.htaccess / mod_rewrite的解决方案吗? [英] What is the .htaccess/mod_rewrite solution for this redirect problem?

查看:171
本文介绍了这究竟是什么重定向问题的.htaccess / mod_rewrite的解决方案吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅编辑的问题底部附近重要信息

我试图让下面的网址

  http://www.example.co.uk/home/templates/cnb/fb_calendar/events/view/289
 

重定向到

<$p$p><$c$c>http://www.example.co.uk/home/index.php?option=com_content&task=view&id=574&Itemid=85&direct=view:289

我想这会工作

 的RewriteCond%{HTTP_HOST} ^ * $
重写规则^家居/模板/ CNB / fb_calendar /事件/视图/([^/\.]+)?$ http://www.example.co.uk/home/index.php?option=com_content&task=view&id=574&Itemid=85&direct=view:$1 [R = 302,L]
 

但事实并非如此。该规则不搞在所有 - 原始地址经历不变。我究竟做错了什么?

我包括下面的整个.htaccess文件:规则我说的是第四个了。 (文件已由的cPanel效用,而不是用手工大多产生的。)

  RewriteEngine叙述上

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^批准/([^/\.]+)/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&approve\=$1" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^不赞成/([^/\.]+)/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&disapprove\=$1" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^直接/([^/\.]+)/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&direct\=$1" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^家居/模板/ CNB / fb_calendar /事件/视图/([^/\.]+)?$ http://www.example.co.uk/home/index.php?option=com_content&task=view&id=574&Itemid=85&direct=view:$1 [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^英国/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=6\&Itemid\=7" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^励志/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=7\&Itemid\=8" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^福音/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=1\&Itemid\=3" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^圣经/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=1\&Itemid\=2" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ DAB / $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=14\&Itemid\=35" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ / $HTTP \:\ / \ / WWW \ .EXAMPLE \ .CO \ .UK \ /家?[R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ ABI / $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=20\&Itemid\=37" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^安妮/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=16\&Itemid\=55" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ BEN / $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=25\&Itemid\=56" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^凯瑟琳/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=22\&Itemid\=57" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^戴维/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=26\&Itemid\=53" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^然/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=21\&Itemid\=58" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^尼克/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=23\&Itemid\=60" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^保罗/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=18\&Itemid\=59" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^罗比/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=17\&Itemid\=61" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^罗伊/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=15\&Itemid\=54" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^露丝/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=19\&Itemid\=62" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^史蒂夫/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=14\&Itemid\=64" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^特雷弗/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=24\&Itemid\=63" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^工作/ $HTTP \:\ / \ / WWW \ .ucb \ .CO \ .UK \ /空缺?[R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^祈祷/ $HTTP \:\ / \ / WWW \ .ucb \ .CO \ .UK \ /祈祷?[R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ yousay / $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=11\&Itemid\=31" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ christmasappeal / $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=12\&Itemid\=32" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^卢克/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=29\&Itemid\=68" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ juls / $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=30\&Itemid\=71" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^电视/ $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=5\&Itemid\=6" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ canigetdab / $? "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=14\&Itemid\=35" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
?重写规则^播放\ / $?HTTP \:\ / \ / WWW \ .EXAMPLE \ .CO \ .UK \ /家庭\ /指数\ .PHP \选项\ = com_wrapper \&放大器; ITEMID \ = 74 \ / [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^书\ / $HTTP \:\ / \ / WWW \ .EXAMPLE \ .CO \ .UK \ /?[R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^书柜\ / $HTTP \:\ / \ / WWW \ .EXAMPLE \ .CO \ .UK \ /?[R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^捐赠\ /?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=12\&Itemid\=32\/" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^海地\ /?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=560\&Itemid\=78\/" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^复活节$HTTP \:\ / \ / WWW \ .EXAMPLE \ .CO \ .UK \ /[R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^社会$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=568\&Itemid\=81" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^组织之参与$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=8\&Itemid\=28" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ CNB $ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ CNB \ /登录$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&login\=" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^布告栏$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^布告栏\ /登录$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&login\=" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ example.co.uk $ [OR]
的RewriteCond%{HTTP_HOST} ^ www.example.co.uk $
重写规则^ bagofhope $HTTP \:\ / \ / WWW \ .ucb \ .CO \ .UK \ / bagofhope[R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ mp3stream $ "http\:\/\/example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=577\&Itemid\=87" [R = 302,L]

的RewriteCond%{HTTP_HOST} ^ * $
重写规则^海报$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=579\&Itemid\=88" [R = 302,L]
 

- 编辑 - 附加信息:

我已经缩小的问题分解到fb_calendar目录 - 如果我用一个目录中的随机名字,而不是fb_calendar它的工作原理。因此,它必须有一些在这个目录是造成这个问题。有此目录中的另一.htaccess文件包含以下内容:

 &LT; IfModule mod_rewrite.c&GT;
   RewriteEngine叙述上
   重写规则^ $应用程序/ Web根目录/ [L]
   重写规则(。*)的应用程序/ Web根目录/ $ 1 [L]
&LT; / IfModule&GT;
 

这是造成问题的原因?我需要一个不会被任何其他的.htaccess文件来实现重写规则/重写的URL路径上的文件夹中的规则。我怎样才能做到这一点?

解决方案

的mod_rewrite 将,在默认情况下,仅使用指令从单个的.htaccess每(内部)要求文件,并用将是最后一个发现有的mod_rewrite 的.htaccess 文件code>指令下您的请求路径。

在这种情况下, ... / fb_calendar /的.htaccess 存在并包含指令,所以他们使用的指令,而不是在你的根。

此外,注意的的指令没有的自动继承,所以做一些像下面会生成一个404,因为指令是present,但 RewriteEngine叙述从来没有在第二个文件打开:

/ htaccess的

  RewriteEngine叙述上

的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^ /index.php?here
 

/test/.htaccess

 重写规则^ /index.php?there
 

请求 - > http://example.com/test/non-existent-path

事实证明,还可以从父规则的.htaccess 使用的 RewriteOptions 指令:

  RewriteEngine叙述上
RewriteOptions继承
 

请注意父规则集导入后,对现有规则集的,所以你的情况的路径将被改写为 ... / fb_calendar / APP / Webroot公司/事件/查看/ .. 的规则在根正在处理的.htaccess 文件(并因此不匹配)。在

您在这种情况下,选择将是要么修改规则,以适应这,或者更容易,您可以在规则正好移动到 ... / fb_calendar /的.htaccess 文件,并调整它在该目录之中。

(Please see important Additional information edited in near the bottom of question)

I'm trying to get the following url

http://www.example.co.uk/home/templates/cnb/fb_calendar/events/view/289

to redirect to

http://www.example.co.uk/home/index.php?option=com_content&task=view&id=574&Itemid=85&direct=view:289

I thought this would work

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^home/templates/cnb/fb_calendar/events/view/([^/\.]+)?$ http://www.example.co.uk/home/index.php?option=com_content&task=view&id=574&Itemid=85&direct=view:$1 [R=302,L]

but it didn't. The rule does not 'engage' at all - original url goes through unchanged. What am I doing wrong?

I'm including the whole .htaccess file below: the rule I'm talking about is the fourth one down. (The file was mostly generated by cpanel utility rather than by hand.)

RewriteEngine on

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^approve/([^/\.]+)/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&approve\=$1" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^disapprove/([^/\.]+)/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&disapprove\=$1" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^direct/([^/\.]+)/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&direct\=$1" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^home/templates/cnb/fb_calendar/events/view/([^/\.]+)?$ http://www.example.co.uk/home/index.php?option=com_content&task=view&id=574&Itemid=85&direct=view:$1 [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^uk/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=6\&Itemid\=7" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^inspirational/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=7\&Itemid\=8" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^gospel/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=1\&Itemid\=3" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^bible/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=1\&Itemid\=2" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^dab/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=14\&Itemid\=35" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "http\:\/\/www\.example\.co\.uk\/home" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^abi/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=20\&Itemid\=37" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^anne/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=16\&Itemid\=55" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^ben/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=25\&Itemid\=56" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^catherine/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=22\&Itemid\=57" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^dave/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=26\&Itemid\=53" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^jan/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=21\&Itemid\=58" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^nick/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=23\&Itemid\=60" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^paul/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=18\&Itemid\=59" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^robbie/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=17\&Itemid\=61" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^roy/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=15\&Itemid\=54" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^ruth/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=19\&Itemid\=62" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^steve/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=14\&Itemid\=64" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^trevor/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=24\&Itemid\=63" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^jobs/?$ "http\:\/\/www\.ucb\.co\.uk\/vacancies" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^prayer/?$ "http\:\/\/www\.ucb\.co\.uk\/prayer" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^yousay/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=11\&Itemid\=31" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^christmasappeal/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=12\&Itemid\=32" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^luke/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=29\&Itemid\=68" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^juls/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=30\&Itemid\=71" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^tv/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=5\&Itemid\=6" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^canigetdab/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=14\&Itemid\=35" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^playlist\/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_wrapper\&Itemid\=74\/" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^books\/?$ "http\:\/\/www\.example\.co\.uk\/" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^bookcase\/?$ "http\:\/\/www\.example\.co\.uk\/" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^donate\/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=12\&Itemid\=32\/" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^haiti\/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=560\&Itemid\=78\/" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^easter$ "http\:\/\/www\.example\.co\.uk\/" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^social$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=568\&Itemid\=81" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^orgs$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=8\&Itemid\=28" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^cnb$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^cnb\/login$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&login\=" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^noticeboard$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^noticeboard\/login$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&login\=" [R=302,L]

RewriteCond %{HTTP_HOST} ^example.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.co.uk$
RewriteRule ^bagofhope$ "http\:\/\/www\.ucb\.co\.uk\/bagofhope" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^mp3stream$ "http\:\/\/example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=577\&Itemid\=87" [R=302,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^posters$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=579\&Itemid\=88" [R=302,L]

-- Edit -- Additional information:

I've narrowed the problem down to the fb_calendar directory - if I use a directory with a random name instead of fb_calendar it works. So it must be something IN this directory that's causing the problem. There is another .htaccess file in this directory with the following contents:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

Is this causing the problem? I need a rewrite rule that will not be effected by any other .htaccess files/rewrite rules in folders on the path in the URL. How can I do this?

解决方案

mod_rewrite will, by default, only use directives from a single .htaccess file per (internal) request, and the .htaccess file used will be the last one found to have mod_rewrite directives down your request path.

In this case, .../fb_calendar/.htaccess exists and contains directives, so they are used instead of the directives in your root.

Furthermore, note that none of the directives are inherited automatically, so doing something like the following will generate a 404, since directives are present, but the RewriteEngine was never turned on in the second file:

/.htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php?here

/test/.htaccess:

RewriteRule ^ /index.php?there

Request -> http://example.com/test/non-existent-path

As it turns out, you can import rules from parent .htaccess files using the RewriteOptions directive:

RewriteEngine On
RewriteOptions inherit

Note that the parent rule set is imported after the existing rule set though, so in your case the path would be rewritten to .../fb_calendar/app/webroot/events/view/... before being processed by the rule in your root .htaccess file (and would therefore not match).

Your options in that case would be to either modify your rule to accommodate for that, or, perhaps more easily, you could just move your rule to the .../fb_calendar/.htaccess file and adjust it for being in that directory.

这篇关于这究竟是什么重定向问题的.htaccess / mod_rewrite的解决方案吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆