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

2023-09-02 09:58:54 作者:时光的别名叫无心

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

下面的htaccess的作品从 http://example.com/offer/something 但如果我打字在 http://example.com/offer?search=something 那么该URL不会更改为 http://example.com/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 http://example.com/offer?search=something to http://example.com/offer/something

The following htaccess works from http://example.com/offer/something but if I typing the http://example.com/offer?search=something then the url is not changing to http://example.com/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