Search code examples
phpapache.htaccessxampp

htaccess file dont work with special character


i have my .htaccess copied from codeigniter ,
i have a page which it should have a href

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

htaccess will get the request correctly if i remove the special characters from the href
the htaccess file:

# 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

Solution

  • With codeigniter you shouldn't be passing URL segments with special characters. Those filters are there for security reasons. Instead, pass them as GET variables.

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

    .. and in your controller

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