.htaccess redirect to index.php

风格不统一 提交于 2021-01-28 08:09:18

问题


My website : theexample.com I modified my .htaccess so that if visitors visits an unkown url it redirects directly to index.php with :

FallbackResource index.php

The problem is that it works only if there is one element after "theexample.com".

for example :

  • "theexample.com/shudhusdfuisdfhisdfh": works and redirects to

  • "theexample.com/sh/fuisd/fhisdfh": doesn't work and doesn't redirect to index.php.


回答1:


You must use absolute path of fallback resource not a relative one:

FallbackResource /index.php

Otherwise FallbackResource index.php will try to load index.php in the provided sub-path e.g. theexample.com/sh/fuisd/fhisdfh will try to load theexample.com/sh/fuisd/index.php which will cause failure as that path doesn't exist resulting in Internal Server Error.




回答2:


This is rewrite. Redirect only non-files links =)

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ index.php

Example: url http://example.com/asdjivuhr/34tv3t will redirext to index.php BUT if you have files(css,js) http://example.com/script.js will stay untooched if file exists!



来源:https://stackoverflow.com/questions/32617169/htaccess-redirect-to-index-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!