简体   繁体   English

如何使PHP将所有子链接重定向到我的索引页面?

[英]How to make php redirect all sublinks to my index page?

如何制作php或htaccess或类似的内容:如果用户尝试输入任何其他链接,请接受此链接:localhost / test / index.php,因此我的网站自动将他重定向到我的index.php链接:localhost / test / index。 PHP

The code that I usually use doesn't require you to specify the directory: 我通常使用的代码不需要您指定目录:

RewriteEngine on
RewriteRule ^(.*)? index.php?uri=$1 [QSA]

Then you can use $_GET['uri'] to see what page the user requested. 然后,您可以使用$_GET['uri']查看用户请求的页面。 Be careful, as this will make all CSS and images and etc also go to your index.php . 小心,因为这会使所有CSS和图像等也转到您的index.php

If you want to exclude any directories from this (say perhaps ./assets/ ), then you can put another .htaccess file inside those directories: 如果要从此排除任何目录(例如./assets/ ),则可以在这些目录中放置另一个.htaccess文件:

RewriteEngine off

this, in .htaccess: 在.htaccess中:

DirectoryIndex index.php
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ localhost/test/index.php [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM