简体   繁体   English

.htaccess网址重写,省略了参数的最后一个字符

[英].htaccess url rewriting omitting last character of the parameter

I am developing a web app in which name of other website are supposed to be given as parameters, am rewriting urls using .htaccess file on my apache web server, this is the code i wrote in my .htaccess file: 我正在开发一个Web应用程序,其中应该以其他网站的名称作为参数,正在使用apache Web服务器上的.htaccess文件重写url,这是我在.htaccess文件中编写的代码:

RewriteEngine On
RewriteRule ^([a-z0-9\_\-]+(\.)[a-z0-9\_\.\-]+)[^(site.php)] site.php?url=$1
RewriteRule ^([a-z0-9\_\-]+(\.)[a-z0-9\_\.\-]+)[^(site.php)]/ site.php?url=$1

I wrote [^(site.php)] this because it was passing site.php as parameter as site.php was a match for my regex. 我写了[^(site.php)]这是因为它通过将site.php作为site.php的参数传递给我的正则表达式。 This is working the right way but the only problem is that the last character of the parameter is omitted, for example, when am writting: 这是正确的方法,但是唯一的问题是参数的最后一个字符被省略,例如,在编写时:

www.mywebsite.com/google.com

its taking google.co and omitting the last m . 它采用google.co并省略了最后一个m If am passing google.co.in , its taking google.co.i and omitting the n . 如果通过google.co.in ,则采用google.co.i并省略n What can be the reason for this? 这可能是什么原因?

Since you use [^(site.php)] (and it doesn't means what you think), it will match the last character of your url. 由于您使用[^(site.php)] (并不代表您的想法),它将与您网址的最后一个字符匹配。 You should use a RewriteCond, you can try : 您应该使用RewriteCond,您可以尝试:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9\_\-]+(\.)[a-z0-9\_\.\-]+)/?$ site.php?url=$1

Wich means : do not rewrite for existing file or directory Wich意思是:不要为现有文件或目录重写

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

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