删除尾随的问号htaccess的(Removing trailing question mark with htaccess)

   IT问题网   2018-03-07 00:00:00

问 题

有人可以帮助我了解这个code?

 #删除尾随?
的rewritecond%{} the_request? http [nc]
重写规则? /%{request_uri}? [r = 301,l]
 

基本上我有一个网站www.example.com正在生成一个链接到www.example.com/index.cfm~~v?我需要它重定向到www.example.com的搜索引擎优化复制的目的。我设法去除index.cfm但?还停留在那里(www.example.com/?)。如果它是最后一个字符的斜线也被删除就好了。我发现这条规则在网上,但我得到一个"的rewritecond:坏标志符"。警报在apache中,并没有做任何事情。

我也有一些网页一样www.example.com/index.cfmterm=test用于搜索,所以我只是想摆脱尾随的问号,而不是当我有连接到它的查询。

该错误是在rewritecond指令。我需要帮助了解情况,为什么它不工作,不只是它的答案。

以防万一这里是整个htaccess的:

rewriteengine叙述上
的rewritebase /

#删除尾随index.cfm
重写规则^ index.cfm(\?)?$ / [r = 301,l]

#海基会网址
setenv sef_request假
重写规则^ [a-z \ d \- ] + / [a-z] \ d + /? /index.cfm/$0 [nc,pt,qsa,e = sef_request:真]
requestheader添加海基会请求%{sef_request} e所
的rewritecond%{http:sef_reques} ^真$ [nc]
重写规则。 -[l]

#删除尾随?
的rewritecond%{} the_request? http [nc]
重写规则? ^%{request_uri}? [r = 301,l]
 

注:我张贴,并没有找到一个解决我的问题之前,没有在网上搜索/计算器

编辑:另外,我发现我重写规则^ index.cfm(\?)$ / [r = 301,l]被拆除index.cfm即使它不是导致404时的最后一件事的网址是什么?我尝试搜索的东西(www.example.com/index.cfmterm=test)如果有人可以纠正我,并解释说,将是巨大的。谢谢你。

edit2:www.example.com/index.cfmterm=testamp;a=dhamp;j=dhjsi不应该被重定向。 www.example.com/a/b/d/f/h/w/d不应被重定向。 www.example.com/index.cfm~~v?和www.example.com/index.cfm应该被重定向到www.example.com。

解决方案
 的rewritecond%{} the_request? http [nc]
重写规则? ^%{request_uri}? [r = 301,l]
 

是行不通的,因为?是正规ex pressions保留字符,你就需要逃避它随着空间。尝试:

 的rewritecond%{the_request} \?\ http [nc]
重写规则^ /?(指标\ .cfm)? /? [r = 301,l]
 

此外,你要根据本条规则你的#删除尾随index.cfm 规则,而不是在最底层。

标签:删除尾随问号



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

URL重写GET参数(URL Rewrite GET parameters)

problem i want my url to look like the following www.web ...

htaccess的从XAMPP转向灯开的Ubuntu 13.10后不工作(启用htaccess的Apache中的Linux服务器)(htaccess is not working after moving from XAMPP to LAMP on ubuntu 13.10 (Enable htaccess in apache linux server))

problem my codeigniter project is running successfullyon ...

查询字符串和放大器;国防部重写(Query Strings & Mod ReWrite)

problem i'm not too inexperienced with rewrite (not a mas ...

在.xml文件PHP的错误?(PHP error in .xml file)

problem ok firstly, i added this line to my .htaccess fil ...

使用Apache的mod_rewrite解析搜索引擎友好的URL(using apache's mod_rewrite to parse SEO friendly URL's)

problem how do i convert something like me.com/profile/2 ...

搜索引擎友好的URL(Search-Engine Friendly URLs)

problem i am working on building my first search-engine f ...

斜杠之后将文字与.htaccess的变量(Turn text after slashes into variables with HTACCESS)

problem i need to pass 3 variables with a url but using s ...

从URL删除字符与htaccess的(Remove Characters from URL with htaccess)

problem hopefully someone can see what i'm do ...

重定向所有的HTML扩展到.PHP(redirect all .html extensions to .php)

problem i want to update all the pages on a website to us ...

需要转义#(哈希/磅)字符在.htaccess重写规则(need to escape # (hash/pound) character in .htaccess rewrite rule)

problem the question is fairly simple but i w ...

如何使用的.htaccess重写规则改变下划线以破折号(How do I use .htaccess RewriteRule to change underscores to dashes)

problem i'm working on a site, and its cms used to save n ...

请求实体太大PHP(Request Entity Too Large PHP)

problem in one of my cakephp site, i got this error. req ...

的.htaccess使用PHP $ _GET缩短网址(.htaccess shorten URL using php $_GET)

problem i need to be able to shorten my page from: mydom ...

Gzip已融为一体pression通过的.htaccess不工作(Gzip compression through .htaccess not working)

problem i have been creating a site and checking it's spe ...

重定向www.subdomain.example.com到subdomain.example.com(redirecting www.subdomain.example.com to subdomain.example.com)

problem i've had some users trying to access a site that ...

添加尾随斜线的.htaccess(Add Trailing Slash .htaccess)

problem i'm trying to get the following effec ...

禁用所有的CGI(PHP,PERL,...)使用的.htaccess目录(Disable all CGI (php, perl, …) for a directory using .htaccess)

problem i have a directory where users can upload files. ...

在某个目录设置为仅附件上的文件内容处理标头?(Set Content-Disposition header to attachment only on files in a certain directory)

problem i've got this this rule in my htaccess file to fo ...

阿帕奇升级到2.4后,内部URL重写不再工作(Internal URL rewrite no longer working after upgrading Apache to 2.4)

problem i need to internally rewrite the base url so that ...

使用codeigniter共享托管服务器上的困惑(Puzzled using codeigniter on shared hosting server)

problem this ones a new on me. i'm transferring a site i ...