重写 URL - 动态 URL 剥离
基本上我想剥离到谷歌新闻部分和只保留最终的 url(不带“http://”)。
我一直在尝试各种解决方案,但到目前为止没有任何效果。 仅供参考 - 我使用 wordpress
任何帮助将不胜感激。
.htaccess 文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} url=(?:http://)?(.*)
RewriteRule presa-bio.php presa-bio.php?var1=%1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I want to rewrite an url like this: http://www.piata-bio.ro/presa-bio.php?var1=http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNHmU7U7bXtlH9Lo8dXfBs64PqxgbA&url=http://www.eva.ro/divertisment/stiri/un-nou-concept-de-magazin-articol-35491.html
to something like this : http://www.piata-bio.ro/presa-bio.php?var1=www.eva.ro/divertisment/stiri/un-nou-concept-de-magazin-articol-35491.html
Basically I want to strip to google news part and only remain with the final url (without the "http://").
I've been trying all sorts of solutions but nothing worked so far.
FYI - I use wordpress
Any help would be greatly appreciated.
htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} url=(?:http://)?(.*)
RewriteRule presa-bio.php presa-bio.php?var1=%1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过匹配 rewriteCond 中的查询字符串来完成此操作:(
如果 ?: 不能与 rewriteCond 一起使用,请松开它并在下一个规则中使用 %2 而不是 %1)。
You can do it by matching the query string in a rewriteCond :
(If the ?: does not work with rewriteCond, loose it and use %2 instead of %1 in the next rule).