简体   繁体   English

PHP:如何捕获我的域名后用URL编写的文本

[英]PHP: How to catch text written in url after my domain name

Please see the sample link/ senario below. 请参阅下面的示例链接/ senario。

www.mydomain.com/khaled www.mydomain.com/khaled

Default page on "www.mydomain.com" is index.php. “ www.mydomain.com”上的默认页面是index.php。 There is no folder or file named "khaled". 没有名为“ khaled”的文件夹或文件。 When the above URL is typed, i want index.php to be called and check the name "khaled" in database and show the relevent profile. 当键入以上URL时,我希望调用index.php并在数据库中检查名称“ khaled”并显示相关事件配置文件。

Problem: When i type the above URL error 404 is displayed. 问题:当我键入以上URL时,显示错误404。

.htaccess is an option but dont know what to write in it. .htaccess是一个选项,但是不知道该写什么。 tried the following line but it returned "Internal server error". 尝试了以下行,但返回“内部服务器错误”。

RewriteRule ^([^/]+)$ index.php?i=$1&p=$2&%{QUERY_STRING} [L]

$_SERVER['REQUEST_URI'] will hold this information in PHP. $_SERVER['REQUEST_URI']将在PHP中保存此信息。 Your htaccess redirect should look something like: 您的htaccess重定向应类似于:

RewriteEngine On
RewriteRule ^([^/\.]+)/?$ /index.php?i=$1 [L]

Then in index.php $_GET['i'] will hold the value of whatever is in the URL after the domain 然后在index.php中, $_GET['i']将保留域后URL中的值

You can obviously add more parameters in the same way, such as: 您显然可以以相同的方式添加更多参数,例如:

RewriteEngine On
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?i=$1&j=$2 [L]

Then use $_GET['i'] and $_GET['j'] for your variables in PHP 然后将$_GET['i']$_GET['j']用于PHP中的变量

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

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