【问题标题】:htaccess file dont work with special characterhtaccess 文件不适用于特殊字符
【发布时间】:2021-09-05 18:08:54
【问题描述】:

我从 codeigniter 复制了我的 .htaccess
我有一个页面,它应该有一个 href

<a href="/notification/<?= rawurlencode(urlencode($tab['href']))?>">

如果我从 href
中删除特殊字符,htaccess 将正确获取请求 htaccess 文件:

# Disable directory browsing
Options All -Indexes

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
      RewriteRule ^ %1 [L,R=301]

    # Rewrite "www.example.com -> example.com"
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to the front controller, index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

    # Ensure Authorization header is passed along
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule>

ServerSignature Off

【问题讨论】:

    标签: php apache .htaccess xampp


    【解决方案1】:

    使用 codeigniter,您不应该传递带有特殊字符的 URL 段。出于安全原因,这些过滤器在那里。而是将它们作为 GET 变量传递。

    <a href="/notification?tab=<?=rawurlencode(urlencode($tab['href']))?>">
    

    .. 在你的控制器中

    class Notification extends CI_Controller {
        public function __construct() {
          parent::__construct();
        }
        public function index() {
          $tab = $this->input->get('tab'); 
        }
    

    【讨论】:

    • 我没有使用 codeigniter,我只是复制了文件并创建了自己的框架,但我允许路由像这样'notification?href/{url}',它现在正在工作
    猜你喜欢
    • 2014-08-09
    • 2016-03-03
    • 1970-01-01
    • 2016-09-13
    • 2019-09-17
    • 1970-01-01
    • 2016-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多