htaccess redirect if URL contains a certain string

前端 未结 4 1398
挽巷
挽巷 2020-11-30 00:35

How would I write a .htaccess redirect rule if the URL contains a certain word?

e.g. if it contains foobar then redirect to index.php

4条回答
  •  一整个雨季
    2020-11-30 01:19

    If url contains a certen string, redirect to index.php . You need to match against the %{REQUEST_URI} variable to check if the url contains a certen string.

    To redirect example.com/foo/bar to /index.php if the uri contains bar anywhere in the uri string , you can use this :

    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} bar
    RewriteRule ^ /index.php [L,R]
    

提交回复
热议问题