首页 > 解决方案 > 如何使用 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 页面上的查询字符串中获取用户/登录名

标签: php.htaccessurl-rewriting

解决方案


尝试这个

你的.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; 

我认为这对你有帮助:)

谢谢


推荐阅读