特定ajax url的htaccess重写规则

时间:2015-11-19 13:21:35

标签: ajax wordpress apache .htaccess mod-rewrite

我正在使用

DELIMITER $$
CREATE PROCEDURE `getFinal11`(IN `param_name` VARCHAR(255), OUT `result` VARCHAR(65535))
BEGIN
  DECLARE `next_leg1_name` VARCHAR(255);
  DECLARE `next_leg2_name` VARCHAR(255);

  SELECT `leg1` INTO `next_leg1_name` 
  FROM `matrix` 
  WHERE `username` = `param_name`;

  SELECT `leg2` INTO `next_leg2_name`
  FROM `matrix`
  WHERE `username` = `param_name`;

  IF `next_leg1_name` <> '' AND  `next_leg2_name` = '' THEN
    CALL `getFinal11`(`next_leg1_name`, `result`);
    SET `result` := CONCAT(`next_leg1_name`, ',', IFNULL(`result`, ''));
  END IF; 

  IF `next_leg2_name` <> '' AND `next_leg1_name` = '' THEN
    CALL `getFinal11`(`next_leg2_name`, `result`);
    SET `result` := CONCAT(`next_leg2_name`, ',', IFNULL(`result`, ''));
  END IF;  

  IF `next_leg2_name` <> '' AND `next_leg1_name` <> '' THEN
    CALL `getFinal11`(`next_leg2_name`, `result`);
    CALL `getFinal11`(`next_leg1_name`, `result`);
    SET `result` := CONCAT(`next_leg2_name`, ',', IFNULL(`result`, ''));
    SET `result` := CONCAT(`next_leg1_name`, ',', IFNULL(`result`, ''));
  END IF;  

  IF `next_leg2_name` = '' AND `next_leg1_name` = '' THEN
    SET `result` := '';
  END IF;
END$$
DELIMITER ;

保护未登录用户使用admin-ajax.php调用的worpdress文件。但这会打破所有访问者的ajax - 所以有些东西对非注册用户不起作用。

我怎样才能为特定网址指定一个重写文件,例如:

RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule ^wp-admin/admin-ajax.php(.*)$ dl-file.php?file=$1 [QSA,L]

id将是文件的编号。 有没有办法用htaccess做到这一点?

我使用dl-file.php

关注了用户hakre https://wordpress.stackexchange.com/questions/37144/how-to-protect-uploads-if-user-is-not-logged-in

谢谢!

AD

1 个答案:

答案 0 :(得分:1)

您可以根据RewriteCond变量添加另一个%{QUERY_STRING}来定位特定网址:

RewriteCond %{QUERY_STRING} (?:^|&)action=ajax_request&fn=download&id= [NC]
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule ^wp-admin/admin-ajax\.php$ dl-file.php?file=$1 [QSA,L]