简体   繁体   English

Htaccess url用2个vars重写

[英]Htaccess url rewrite with 2 vars

I'm having problems with my htaccess. 我的htaccess有问题。 I've got this url: www.mypage.com/search.php?region=EUW&summonerName=Summonername . 我有这个网址: www.mypage.com/search.php?region=EUW&summonerName=Summonername And this in my .htaccess file: 这在我的.htaccess文件中:

RewriteRule ^(.*)/(.*)/ https://www.mypage.com/search.php?region=$1&summonerName=$2 [L]

When I try to go to www.mypage.com/EUW/Summonername it returns 404. 当我尝试访问www.mypage.com/EUW/Summonername它返回404。

Of course I've searched a lot about htaccess url rewrite before make this thread but, nothing works. 当然,在制作这个帖子之前,我已经搜索了很多关于htaccess url重写的内容,但是没有任何效果。 What's wrong with the code? 代码有什么问题? Cheers. 干杯。

Edit: I've found the way using: RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.*)/(.*)/?$ search?region=$1&summonerName=$2 Now I can do urls like https://www.mypage.com/text/text without problems, but I still having a problem. 编辑:我找到了使用方法: RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.*)/(.*)/?$ search?region=$1&summonerName=$2现在我可以做像https://www.mypage.com/text/text这样的网址没有问题,但我仍然有问题。 In my form from index.php it still redirecting to https://www.mypage.com/search.php?region=text&summonerName=text and I don't even don't know why. 在index.php的表单中,它仍然重定向到https://www.mypage.com/search.php?region=text&summonerName=text ,我甚至不知道为什么。 Some idea? 有些想法? Cheers Ladies and Gentlemans. 干杯女士们和绅士们。

尝试这个 :

RewriteRule ^(.*)\/(.*)$ /search.php?region=$1&summonerName=$2 [L]

I think your problem is the protocol. 我认为你的问题是协议。 It looks like you're trying to internally rewrite https and I don't believe it will let you do that for security purposes. 看起来你正试图在内部重写https ,我不相信它会让你出于安全目的这样做。 That's why it's probably still redirecting. 这就是它可能仍在重定向的原因。

You should use relative paths. 你应该使用相对路径。 Try it this way and see if it works for you. 试试这种方式,看看它是否适合你。

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /search.php?region=$1&summonerName=$2 [L]

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

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