Redirect all traffic to index.php using mod_rewrite

前端 未结 5 1161
Happy的楠姐
Happy的楠姐 2020-11-28 14:29

I\'m trying to build a url shortener, and I want to be able to take any characters immediately after the domain and have them passed as a variable url. So for example

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 15:17

    To rewrite all requests to /index.php ,you can use :

    RewriteEngine on
    
    
    RewriteCond %{REQUEST_URI} !^/index.php$
    RewriteRule ^(.+)$ /index.php?url=$1 [NC,L]
    

    The RewriteCondition RewriteCond %{REQUEST_URI} !^/index.php$ is important as it excludes the rewrite destination we are rewriting to and prevents infinite looping error.

提交回复
热议问题