如何更改浏览器通过htaccess的网址?

编程入门 行业动态 更新时间:2024-10-23 23:24:26
本文介绍了如何更改浏览器通过htaccess的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想通过htaccess的从改变我的网址 example/offer?search=something 以 example/offer/something

下面的htaccess的作品从 example/offer/something 但如果我打字在 example/offer?search=something 那么该URL不会更改为 example/offer/something 。

RewriteEngine叙述上 重写规则^报价/([^ /] *)$ /报价?搜索= $ 1 [L]

我应该使用的RewriteCond?什么是正确的htaccess的在这种情况下?

我试图使它在Laravel framwork。我只有一个htaccess的,这是内容,目前:

< IfModule mod_rewrite.c> < IfModule mod_negotiation.c>     选项​​-MultiViews < / IfModule> RewriteEngine叙述上 #重定向结尾的斜杠... 重写规则^(。*)/ $ / $ 1 [L,R = 301] #拉手前端控制器... 的RewriteCond%{} REQUEST_FILENAME!-d 的RewriteCond%{} REQUEST_FILENAME!-f 重写规则^的index.php [L] 的RewriteCond%{QUERY_STRING} ^搜索=( - A-ZA-Z0-9] +) 重写规则^报价$ /报价/%1? [R = 301,L] 重写规则^报价/([^ /] *)$ /报价?搜索= $ 1 [L] < / IfModule>

解决方案

更新:完整的.htaccess:

< IfModule mod_rewrite.c> < IfModule mod_negotiation.c>     选项​​-MultiViews < / IfModule> RewriteEngine叙述上 的RewriteBase / #重定向结尾的斜杠... 重写规则^(。*)/ $ / $ 1 [L,R = 301] #与GET参数重定向URL以pretty的网址 ?的RewriteCond%{THE_REQUEST} \ S / +提供\搜索=([^ \ S&功放;] +)[NC] 重写规则^ /报价/%1? [R = 301,L] #重写从pretty的URL实际手柄 重写规则^(报价/ [^ /] +)/ $的index.php / $ 1 [L,QSA] #拉手前端控制器... 的RewriteCond%{} REQUEST_FILENAME!-d 的RewriteCond%{} REQUEST_FILENAME!-f 重写规则^的index.php [L] < / IfModule>

如何prevents循环:从浏览器和接收阿帕奇 THE_REQUEST 变量重新presents原始请求的它并不会执行其他重写规则后覆盖,unline %{REQUEST_URI} 这被其他规则之后覆盖。这个变量的例子值为 GET /index.php?id=123 HTTP / 1.1

I want to change my url by htaccess from example/offer?search=something to example/offer/something

The following htaccess works from example/offer/something but if I typing the example/offer?search=something then the url is not changing to example/offer/something.

RewriteEngine On RewriteRule ^offer/([^/]*)$ /offer?search=$1 [L]

Should I use "rewritecond"? What is the correct htaccess in this case?

I try make it in Laravel framwork. I have only one htaccess and this is the content, currently:

<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] RewriteCond %{QUERY_STRING} ^search=([-a-zA-Z0-9]+) RewriteRule ^offer$ /offer/%1? [R=301,L] RewriteRule ^offer/([^/]*)$ /offer?search=$1 [L] </IfModule>

解决方案

UPDATE: Full .htaccess:

<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteBase / # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # redirect URL with GET parameter to pretty URL RewriteCond %{THE_REQUEST} \s/+offer\?search=([^\s&]+) [NC] RewriteRule ^ /offer/%1? [R=301,L] # rewrite from pretty URL to actual handle RewriteRule ^(offer/[^/]+)/?$ index.php/$1 [L,QSA] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>

How it prevents looping: THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of other rewrite rules, unline %{REQUEST_URI} which gets overwritten after other rules. Example value of this variable is GET /index.php?id=123 HTTP/1.1

更多推荐

如何更改浏览器通过htaccess的网址?

本文发布于:2023-11-01 20:26:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550325.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何更改   浏览器   网址   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!