简体   繁体   English

单文件无查询字符串的mod_rewrite问题

[英]mod_rewrite issue with single file no query string

Trying to use mod-rewrite to alter the address bar versus the actual page that's being loaded. 尝试使用mod-rewrite来更改地址栏与正在加载的实际页面。 It works great when I have a query string to use, but I need to do it without a query string, just a straight up pretty url. 当我要使用查询字符串时,它的效果很好,但是我需要在没有查询字符串的情况下执行此操作,而只是使用一个简单的URL。

It seems to be that without a query string, straight mod_rewrites to files just shows the actual filename with extension. 似乎没有查询字符串,直接将mod_rewrites写入文件仅显示带有扩展名的实际文件名。

Here's what my htaccess looks like: 这是我的htaccess的样子:

Options +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]

This works: 这有效:

RewriteRule ^admin/account/([^/]*)/$ /adminconfig/account.php?id=$1 [L]

This doesn't: 这不是:

RewriteRule ^admin/account/$ /adminconfig/account.php [L]

What's happening is that in the address bar I see: 发生了什么事,我在地址栏中看到了:

example.com/adminconfig/account.php/

should be: 应该:

example.com/admin/account/

You need to do your rules like this. 您需要执行以下规则。 I also made sure multiviews was off 我还确保关闭了多视图

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin/([^/]+)/?$ /adminconfig/$1.php [L]

This rule should allow you to use a URL like this below in the address bar 该规则应允许您在地址栏中使用如下所示的URL

example.com/admin/account/

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

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