rewriterule在.htaccess文件中不起作用

时间:2021-08-03 10:51:58

i am using .htacess file for rewrite url. i have written rewritrule that is working. but one issue with its. That is when page is completely loaded url in browser again changes in querystring format. my code is below. please help how can i set it.

我正在使用.htacess文件重写网址。我写了有效的rewritrule。但它有一个问题。也就是当页面完全加载时,浏览器中的url再次以querystring格式更改。我的代码如下。请帮助我如何设置它。

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.

请帮忙谢谢。

3 个解决方案

#1


0  

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; you're actually matching , in the URL. If that's the designed behavior, you only need one comma (you have 2).

这应该工作。另外,看起来你正在使用,作为重写中的分隔符 - 这是不必要的,你不需要在char类型之间使用分隔符;你实际上在URL中匹配。如果这是设计的行为,你只需要一个逗号(你有2个)。

#2


0  

You're redirecting yourself to the wrong URL by setting the R flag. 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:

您通过设置R标志将自己重定向到错误的URL。这表明应该强制进行外部重定向。您可以添加L标志,因此在此之后不会执行重写规则:

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

#3


0  

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. Which means you have to make sure path of these files start either with http:// or a slash /.

然后确保在css,js,images文件中使用绝对路径而不是相对路径。这意味着您必须确保这些文件的路径以http://或斜杠/开头。

#1


0  

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; you're actually matching , in the URL. If that's the designed behavior, you only need one comma (you have 2).

这应该工作。另外,看起来你正在使用,作为重写中的分隔符 - 这是不必要的,你不需要在char类型之间使用分隔符;你实际上在URL中匹配。如果这是设计的行为,你只需要一个逗号(你有2个)。

#2


0  

You're redirecting yourself to the wrong URL by setting the R flag. 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:

您通过设置R标志将自己重定向到错误的URL。这表明应该强制进行外部重定向。您可以添加L标志,因此在此之后不会执行重写规则:

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

#3


0  

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. Which means you have to make sure path of these files start either with http:// or a slash /.

然后确保在css,js,images文件中使用绝对路径而不是相对路径。这意味着您必须确保这些文件的路径以http://或斜杠/开头。