将所有内容重定向到 index.php

Redirect everything to index.php(将所有内容重定向到 index.php)
本文介绍了将所有内容重定向到 index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过分解 $_SERVER['REQUEST_URI'] 然后在结果之间切换来制作干净的 URL.

I'm trying to do clean URLs by exploding $_SERVER['REQUEST_URI'] and then switching between the results.

但是,一旦用户离开 index.php,我假设我需要将他们重定向回 index.php 以处理他们想要的 URL达到.我怎样才能做到这一点?

However, once a user goes outside index.php, I'm assuming I need to redirect them back to index.php in order to process the URL they want to reach. How can I accomplish this?

例如,如果用户访问 www.domain.com/home/johndoe/... 我想要 index.php (domain.com/index.php) 以便它可以通过 request_uri 处理 /home/johndoe/.

So for instance, if the user goes to www.domain.com/home/johndoe/... I'd like index.php (domain.com/index.php) to be hit so that it can process the /home/johndoe/ via request_uri.

推荐答案

.htaccess:

RewriteEngine on
RewriteBase /
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule  ^(.*)$ index.php?param=$1 [QSA,L]

这篇关于将所有内容重定向到 index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)