Rewriting URL with .htaccess local in XAMPP

前端 未结 3 847
心在旅途
心在旅途 2020-12-10 23:19

My .htacces begins with

   RewriteEngine on
   RewriteBase /

(I tried it also without RewriteBase...)

I tried all of the following

3条回答
  •  孤城傲影
    2020-12-11 00:04

    Here's the solution to change links from http://www.domain.tld/index.php?page=blog to http://www.domain.tld/blog is:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^\w+$ index.php?page=$0 [L]
    RewriteCond %{THE_REQUEST} index\.php
    RewriteCond %{QUERY_STRING} ^page=(\w+)$
    RewriteRule ^index\.php$ /%1? [R=301,L]
    

    and for links like: http://www.domain.tld/index.php?page=single_news&id=1&headline=This%20Is%20A%Headline

    the solution is:

    RewriteRule ^blog/(\d+)-([\w-]+)$ index.php?page=single_news&id=$1&headline=$2
    

    After using this code, links looks like this: http://www.domain.tld/blog/2-this-is-a-headline

提交回复
热议问题