How to avoid "?" using regex in .htaccess for mod_rewrite

I need to avoid the "?" character in the url so that it works with rewritten urls like search / why-is-it? -1.html

I currently have the following .htaccess

RewriteEngine on RewriteRule ^search/(.*)-([0-9]+).html$ index.php?search=$1&page=$2 [L] 

thanks

+4
source share
1 answer

Do not put a question mark in your URLs. ? reserved to start the query string.

To put it in the url, write it as %3F .

Read the RFC and this answer .

Update

If you use PHP (and it looks like you), you can do something like this (the requested page is index.php/inter?net ) ...

 <?php var_dump($_GET); $urlTokens = explode('/', $_SERVER['REQUEST_URI']); $slug = end($urlTokens); var_dump($slug); 

Outputs

 array(1) { ["net"]=> string(0) "" } string(9) "inter?net" 

You can see that $_GET messy.

+6
source

Source: https://habr.com/ru/post/1341908/


All Articles