.htaccess 重写规则在未定义的页面上结束
这是我的根目录的.htaccess 重写规则在未定义的页面上结束,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,这是我的根目录的.htaccess: RewriteEngine on RewriteCond %{request_filename} -f RewriteRule ^(.*) $1 [L] RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L] 为了缩短URL,我成功地使用了以下内容: RewriteRule ^explore/([^/]+)/?$ index.php?a=e
.htaccess
:
RewriteEngine on
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L]
为了缩短URL,我成功地使用了以下内容:
RewriteRule ^explore/([^/]+)/?$ index.php?a=explore&filter=$1 [NC]
在这种情况下,urlhttps://example.com/index.php?a=explore&filter=latest%20music
变成https://example.com/explore&filter=latest%20music
我的问题从这里开始…如果我缩短此url:
https://example.com/index.php?a=search&q=something
使用此规则:
RewriteRule ^search/([^/]+)/?$ index.php?a=search&q=$1 [NC]
重定向不起作用,我最终进入了一个未定义的页面
这是用于搜索的my JS函数:
function manageResults() {
var q = $("#search").val();
liveLoad('search&q='+q.replace(' ','+'));
}
这是我的完整.htaccess
:
RewriteEngine on
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L]
RewriteRule ^explore/([^/]+)/?$ index.php?a=explore&filter=$1 [NC]
RewriteRule ^search/([^/]+)/?$ index.php?a=search&q=$1 [NC]
RewriteRule ^welcome/([^/]+)/?$ index.php?a=welcome&filter=$1 [NC]
Myfunction.js
用于实时搜索:
function liveSearch() {
var q = $('#search').val();
// If the query starts with #, do not execute anything
if(q == '#') {
$(".search-container").hide();
$(".search-content").remove();
return false;
}
// Check the notification state
if(typeof notificationState != 'undefined') {
showNotification('close');
}
// Search if the hashtag is typed
if(q.indexOf('#') === -1) {
var y = 'q';
var url = 'people';
$('#search').keypress(function(x){if(x.keyCode==13){q=$(this).val();if(q!=this.defaultValue){document.location='search&'+y+'='+q.replace(' ','+')}}});
} else {
var y = 'filter';
var url = 'tags';
$('#search').keypress(function(x){if(x.keyCode==13){q=$(this).val();if(q!=this.defaultValue){document.location='explore&'+y+'='+q.replace('#','')}}});
}
// If the text input is 0, remove everything instantly by setting the MS to 1
if(q == 0) {
var ms = 0;
} else {
$('.search-container').show();
$('.search-container').html('<div class="search-content"><div class="search-results"><div class="message-inner"><div class="retrieving-results">Retrieving Results</div> <div class="preloader-left preloader-dark"></div></div></div></div>');
var ms = 200;
}
// Start the delay (to prevent some useless queries)
setTimeout(function() {
if(q == $('#search').val()) {
if(q == 0) {
$(".search-container").hide();
$(".search-content").remove();
} else {
$.ajax({
type: "POST",
url: "https://example.com/requests/load_"+url+".php",
data: 'q='+q+'&start=1&live=1', // start is not used in this particular case, only needs to be set
cache: false,
success: function(html) {
$(".search-container").html(html).show();
}
});
}
}
}, ms);
}
函数liveSearch(){
var q=$('#search').val();
//如果查询以#开头,则不执行任何操作
如果(q='#'){
$(“.search container”).hide();
$(“.search content”).remove();
返回false;
}
//检查通知状态
if(通知状态的类型!=“未定义”){
显示通知(“关闭”);
}
//搜索是否键入了hashtag
if(q.indexOf('#')=-1){
变量y='q';
var url='人';
$('#search').keypress(函数(x){if(x.keyCode==13){q=$(this.val();if(q!=this.defaultValue){document.location='search&'+y+'='+q.replace('++')});
}否则{
变量y='过滤器';
var url='标记';
$('#search').keypress(函数(x){if(x.keyCode==13){q=$(this.val();if(q!=this.defaultValue){document.location='explore&'+y+'='+q.replace('#','}});
}
//如果文本输入为0,通过将MS设置为1立即删除所有内容
如果(q==0){
var-ms=0;
}否则{
$('.search container').show();
$('.search container').html('检索结果');
var-ms=200;
}
//启动延迟(防止一些无用的查询)
setTimeout(函数(){
if(q=$('#search').val()){
如果(q==0){
$(“.search container”).hide();
$(“.search content”).remove();
}否则{
$.ajax({
类型:“POST”,
url:“https://example.com/requests/load_“+url+”.php”,
data:'q='+q+'&start=1&live=1',//在这种特殊情况下不使用start,只需要设置
cache:false,
成功:函数(html){
$(“.search container”).html(html).show();
}
});
}
}
},ms);
}
“重定向无效”-尝试通过添加R
标志临时更改为外部重定向。它是否重定向到正确的URL?尽管/search/
看起来似乎应该由您最初的重写规则处理
?如果您使用JS从URL获取信息以执行搜索,则可能需要更新JS(因为URL现在已更改)。@w3d刚刚添加了R
标志,但它不起作用,即使我直接输入URL。这项功能仅用于添加,如果添加了/index.php?a=search&q=something
,则还需要在替换前加上斜杠,即/index.php?…
,但你是说根本没有重定向吗?但正如我也提到的,这看起来也是由第一个规则集来处理的——因此可能存在冲突。由于指令的顺序很重要,您可以发布整个.htaccess文件吗?@w3d我只是编辑我的问题。由于某种原因,如果我试图直接访问该页面,我会重定向到/welcome
页面,该重定向不能由上面发布的指令引起。(?)