如何通过URL接受GET参数,但没有“.php?参数=值”
How to accept GET arguments through a URL, but without having ".php?argument=value"
可能的重复项:
如何:在 PHP 中重写 URL?
网站如何使用您直接在 URL 中提供的参数?
例如,您可以访问:
http://isup.me/www.google.com
然后,该站点上的脚本可以使用值 www.google.com 来查看站点是否已启动。
我可以用:
http://isup.me/index.php?url=ww.google.com
$url = $_GET['url'];
但这不是很干净,我很想知道它是如何以另一种方式完成的。
多谢!PIMVDB指出,这是这个问题的重复:
如何在PHP中进行URL重写?
你需要ModRewrite。
# Turn on URL rewriting
RewriteEngine On
RewriteBase /
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [L]
这完全取决于您的服务器配置。
每次我这样做时,我都使用mod_rewrite
用于 apache:(.htaccess 文件(
RewriteEngine On
RewriteBase /
#If not an existing File
RewriteCond %{REQUEST_FILENAME} !-f
#AND If not an existing Directory
RewriteCond %{REQUEST_FILENAME} !-d
#rewrite to test.php
RewriteRule ^(.*) /test.php?site=$1 [L]
您可以使用 php 文件进行测试:
<?php
print_r($_REQUEST);
你可以用mod_rewrite
!.htaccess 文件内容示例:
RewriteEngine On
RewriteCond %{REQUEST_URI}
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^([^/]*)$ index.php?get_var_name=$1
相关文章:
- 带有输入参数的Javascript/PHP中的XMLHTTPrequests
- 如何使用OnClick事件通过参数调用来调用PHP函数
- 当客户端将两个按钮的javascript函数参数修改为相同时,SQL/PHP会更新多行
- 使用PHP和Javascript在函数内部传递alphaneumeric值作为参数时出错
- 参数使用AJAX的PHP POST不起作用
- 如何在jQuery AJAX中使用参数调用PHP函数
- 如何使用PHP获取h1的内容以用于Twitter数据文本参数
- 使用 PHP 生成的按钮生成 POST 请求,这些按钮调用带有参数的 javascript 函数
- 我想在 javascript 中调用一个 php 函数,并在其中传递两个数组作为参数
- 无法访问 PHP 中的参数,使用 Serialize 从 jQuery 发布值
- json_encode,php作为javascript函数的参数
- javascript变量到php函数作为参数
- 使用javascript中的模块参数(php中的javascript)
- 传递php字符串作为php脚本中调用的javascript函数的参数
- jquery没有向php发送参数
- 如何传递PHP字符串作为JS函数参数
- javascript$.post将参数传递到外部PHP文件
- 访问 URL 参数 - PHP 和 Angular JS
- 可能改变一个参数php?从控制器
- 通过参数PHP将变量传递给AJAX函数