沃梦达 / 编程问答 / php问题 / 正文

将所有内容重定向到 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:将所有内容重定向到 index.php

基础教程推荐