htaccess的删除.php然后让查询字符串 [英] htaccess remove .php and keep query string

查看:236
本文介绍了htaccess的删除.php然后让查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的.htaccess文件现在。

  RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$ $ 1.PHP [NC,L,QSA]
 

这工作,因为它使我的网页访问时不使用PHP扩展的事实。

 旧= domain.com/test.php
新= domain.com/test
 

坏的是,当我把得到的数据与下面的链接中的数据不通过。我认为QSA选择这样做,什么交易?

  domain.com/test?id=1
 

解决方案

匹配整个查询字符串,并使用一个反向引用应该把它附加到您的新网址。

  RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{QUERY_STRING} ^(。*)$
重写规则^(。*)$ $ 1.PHP?%1 [NC,L,QSA]
 

Here is my .htaccess file right now.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [NC,L,QSA]

This works in the fact that it makes my pages accessible when not using the .php extension.

Old = domain.com/test.php
New = domain.com/test

The bad thing is that when I send get data with the following link the data is not passed. I thought the QSA option did that, whats the deal?

domain.com/test?id=1

解决方案

Matching the entire query string and appending it to your new URL using a back-reference should work.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ $1.php?%1 [NC,L,QSA]

这篇关于htaccess的删除.php然后让查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆