简体   繁体   English

rewriterule在.htaccess文件中不起作用

[英]rewriterule is not working in .htaccess file

i am using .htacess file for rewrite url. 我正在使用.htacess文件重写URL。 i have written rewritrule that is working. 我已经写了起作用的rewritrule。 but one issue with its. 但是它的一个问题。 That is when page is completely loaded url in browser again changes in querystring format. 那就是当页面完全加载后,浏览器中的url再次以querystring格式更改。 my code is below. 我的代码如下。 please help how can i set it. 请帮助我如何设置它。

RewriteRule ^/?([0-9]+)/([A-Za-z,0-9,-]+)/?$ /mysite.com/player.php?/$1/$2 [R] 

i write this url 我写这个网址

www.mysite.com/4/title

and its redirected into 并重定向到

www.mysit.com/player.php?/4/title

its working fine but when page loaded completely in browser address is again 它的工作正常,但当页面完全加载到浏览器地址中时再次出现

www.mysite.com/player.php?/4/title 

not remain in this format 不保留此格式

(www.mysit.com/4/title)

Please help Thanks. 请帮助谢谢。

You're redirecting yourself to the wrong URL by setting the R flag. 通过设置R标志将您重定向到错误的URL。 That indicates that an external redirect should be forced. 这表明应该强制进行外部重定向。 You could add the L flag instead, so no rewrite rules are executed after this one: 您可以改为添加L标志,因此在此之后不会执行任何重写规则:

RewriteRule ^/?([0-9]+)/([A-Za-z,0-9,-]+)/?$ /mysite.com/player.php?/$1/$2 [L]

The [R] flag makes you physically redirect to the new address, rather than just rewriting the URL behind the scenes. [R]标志使您可以物理重定向到新地址,而不仅仅是在后台重写URL。

RewriteRule ^/?([0-9]+)/([A-Za-z,0-9-]+)/?$ /mysite.com/player.php?/$1/$2

This should work. 这应该工作。 Also, looks like you're using , as separator in the rewrite - that's unnecessary, you don't need separators between char types; 另外,看起来您正在使用,作为重写中的分隔符-不必要,您不需要在char类型之间使用分隔符; you're actually matching , in the URL. 你实际上匹配,在URL中。 If that's the designed behavior, you only need one comma (you have 2). 如果这是设计的行为,则只需一个逗号(您就有2个)。

First you need to have this rule: 首先,您需要遵循以下规则:

RewriteEngine On

RewriteRule ^([0-9]+)/([A-Za-z,0-9,-]+)/?$ /player.php?/$1/$2 [L,QSA]

Then make sure to use absolute path in your css, js, images files rather than a relative one. 然后确保在您的css,js,图像文件中使用绝对路径,而不要使用相对路径。 Which means you have to make sure path of these files start either with http:// or a slash / . 这意味着您必须确保这些文件的路径以http://或斜杠/开头。

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

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