简体   繁体   English

Mod_rewrite URL反之亦然

[英]Mod_rewrite url vice versa redirect

I can't understand and can't find the needed clear information about it. 我无法理解,也无法找到所需的明确信息。

Is it even possible to rewrite with mod_rewrite localhost/mysite/index.php?a=search url to localhost/mysite/search ? 甚至可以用mod_rewrite localhost/mysite/index.php?a=search重写localhost/mysite/index.php?a=search url到localhost/mysite/search

I have tried with wikipedia http://en.wikipedia.org/w/index.php?title=Dog , then it immediately redirects to https://en.wikipedia.org/wiki/Dog . 我已经尝试了Wikipedia http://en.wikipedia.org/w/index.php?title=Dog ,然后立即将其重定向到https://en.wikipedia.org/wiki/Dog I want similar thing. 我想要类似的东西。

I've tried this code on my localhost site .htaccess file: 我已经在本地站点.htaccess文件中尝试了以下代码:

RewriteRule ^([a-z]+)/?$ index.php?a=$1 [NC,L]

it worked when I tried to type in browser something like localhost/mysite/search but it is only one part of what I want. 当我尝试在浏览器中键入类似localhost/mysite/search类的命令时,它起作用了,但这只是我想要的一部分。 Please answer, I'm absolutely exhausted. 请回答,我绝对精疲力尽。

You need an additional redirect rule for redirecting to pretty URL. 您需要其他重定向规则才能重定向到漂亮的URL。 Have it this way: 有这种方式:

RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php\?a=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]

RewriteRule ^([a-z]+)/?$ index.php?a=$1 [NC,L,QSA]

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

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