简体   繁体   English

.htaccess规则可从静态文件中提供“ bla.php?id = 1”

[英].htaccess rules to serve “bla.php?id=1” from static file

Situation 情况

I have files with names like 我有一些名称如下的文件

bla.php?id=1

( bla.php doesn't exist) that contain plain HTML code (which happens when you mirror a site with wget for example). bla.php不存在)包含纯HTML代码(例如,当您使用wget镜像站点时会发生这种情况)。

Goal 目标

When accessing 访问时

domain.com/bla.php?id=1 

it should serve from the static file bla.php?id=1 instead of bla.php and appending the query string to it. 它应从静态文件bla.php?id=1而不是bla.php ,并向其附加查询字符串。 Works with the question mark in hex, ie. 使用十六进制的问号,即。 domain.com/bla.php%3Fid=1 , but then the URL would change and it shouldn't. domain.com/bla.php%3Fid=1 ,但是URL将会更改,并且不会更改。

Problem 问题

The solution I came up with is to rewrite question marks in the URL to hex internally via .htaccess, which so far I didn't get to work correctly. 我想出的解决方案是将URL中的问号重写为通过.htaccess在内部进行十六进制处理,到目前为止,我仍然无法正常工作。 If anyone has a better idea to reach the goal of serving URLs containing query strings from static files, it would be very appreciated. 如果有人有更好的主意达到服务包含静态文件查询字符串的URL的目标,将不胜感激。 Below is what I tried without luck: 以下是我没有运气的尝试:

RewriteCond %{QUERY_STRING} !=""
RewriteRule ^/(.*) /$1\%3F%{QUERY_STRING}? [NE,L]
We have a solution for this, Please try the below code.

 RewriteCond %{ENV:REDIRECT_STATUS} =""
 RewriteCond %{QUERY_STRING} !=""
 RewriteRule ^(.*) /$1\%3F%{QUERY_STRING}

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

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