php - 如何使用 htaccess 在 index.php 上获取斜杠 url 参数
问题描述
我将在 php 中创建一个项目
当我在地址栏中点击以下网址时 http://10.16.70.70/myproject/user/login
它在下面显示错误
未找到
在此服务器上找不到请求的 URL /jween/user/login。
Apache/2.4.18 (Ubuntu) 服务器在 10.16.70.70 端口 80
我的 htaccess 代码是
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
我想要什么,当我点击这个网址http://10.16.70.70/myproject/user/login
我想使用 htaccess 在我的 index.php 页面上的查询字符串中获取用户/登录名
解决方案
尝试这个
你的.htaccess看起来像这样
Options +FollowSymlinks
Options -Indexes
RewriteEngine On
RewriteBase /myproject/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
你的index.php文件看起来像这样(仅用于测试目的)
<?php
echo "<pre>"; print_r($_GET); echo "</pre>";die;
我认为这对你有帮助:)
谢谢
推荐阅读
- assembly - 生成一个字符串,表示给定二进制数的十进制值
- javascript - 尝试在重新加载时存储单选按钮选择
- ms-access - 通过 Access 查询添加计算的到期日期
- airflow - AirflowException:SSH 操作员错误:没有可用的身份验证方法
- angular - Angular 第三方库组件使用最佳实践建议请求
- node.js - 使用node js做网络爬虫但无法搜索数据
- c# - 触摸特定对象时实例化对象
- javascript - 同时运行客户端和服务器端问题
- swift - Xcode 10.1 和 Swift 语言 4.2.1,我的 Xcode 有语言 swift 4.2 和如何获得 Swift 4.2.1
- hibernate - 有条件的@AttributeOverride Hibernate 注解