简体   繁体   English

如何将数据传递给 php url 而不会出现 404 错误

[英]How to pass data to php url without getting 404 error

I have an index.php in my website hosted at:我的网站中有一个index.php托管在:

https://example.com/api/redirect/index.php

I want to make a url such that : https://example.com/api/redirect/530 will not return an error 404 page.我想制作一个网址: https://example.com/api/redirect/530 : https://example.com/api/redirect/530不会返回错误 404 页面。

Then I will use that number 530 in my index.php to do something.然后我将在我的index.php使用这个数字 530 来做一些事情。 How do I implement that url functionality ?我如何实现那个 url 功能?

Edit: I am new to php and I don't even know what I am looking for here.编辑:我是 php 的新手,我什至不知道我在这里寻找什么。 Even a comment is greatly welcome!甚至评论也非常受欢迎!

ie How do I prevent a 404 error plus get that number 530, in the index.php to perform some operation?即如何防止 404 错误并在 index.php 中获取该数字 530 以执行某些操作?

create .htaccess in your redirect directory with the content below使用以下内容在redirect目录中创建.htaccess

RewriteEngine On
RewriteRule ^(.*)$ index.php?var=$1 [L,QSA]

You can get the param in the index.php by $_GET["var"]您可以通过$_GET["var"]获取 index.php 中的参数

PS: make sure the rewrite module is activated. PS:确保重写模块被激活。 if you use ubuntu you run command a2enmod rewrite to activate it.如果您使用 ubuntu,则运行命令a2enmod rewrite来激活它。

Error 404 is an error when site is not available.错误 404 是站点不可用时的错误。

You don't have a route for it perhaps,你可能没有路线,

or Your .htaccess file is wrong written或者你的 .htaccess 文件写错了

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

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