简体   繁体   English

重定向而不是重写.htaccess规则

[英]Redirect instead of Rewrite .htaccess rule

I once asked this question : 我曾经问过这个问题

I would like to create redirects so anyone who will enter this URL 我想创建重定向,以便任何将输入此URL的人

mywebsite.com/abc will redirect to mywebsite.com/profile.php?id=abc
mywebsite.com/xyz will redirect to mywebsite.com/profile.php?id=xyz
mywebsite.com/mno will redirect to mywebsite.com/profile.php?id=mno

I was given with the following: 我得到以下信息:

RewriteEngine On
RewriteRule ^([^/]*)$ /profile.php?id=$1 [L]

Every mywebsite.com/profile.php?id= * is being replaced to mywebsite.com/* 每个mywebsite.com/profile.php?id= *都将替换为mywebsite.com/*

Instead of rewriting is it possible to redirect as per my original question? 除了重写,是否可以按照我的原始问题进行重定向?

As I said the only way would be to direct the user to the php script. 正如我所说,唯一的方法是将用户定向到php脚本。 If you are trying to clean up the look of the URL without even redirecting you could do this: 如果您尝试清理URL的外观而不进行重定向,则可以执行以下操作:

if (!isset($_GET['id']) {
 $uri = array_filter(explode('/',$_SERVER['REQUEST_URI']));
 if ($uri[1]) {
  $_GET['id'] = $uri[1];
 }
}

Then you could access the profile at /profile.php/abc or profile.php?id=abc. 然后,您可以访问/profile.php/abc或profile.php?id = abc上的配置文件。

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

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