URL重写规则在.htaccess的index.php的查询参数重写、规则、参数、URL

2023-09-02 00:52:50 作者:亽无人知晓得温柔彡

例如网址: -

www.domain.com/index.php?bob www.domain.com/index.php?jane www.domain.com/index.php?fred

需要重写,如: -

www.domain.com/bob www.domain.com/jane www.domain.com/fred

曾尝试与许多变化,但现在最接近我能得到的是: -

www.domain.com/?bob www.domain.com/?jane www.domain.com/?fred

下在.htaccess实现这一点......

 重写规则^(。*)$的index.php?$ 1 [L,QSA]
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,}  S(。*)/指数 .PHP [NC]
重写规则^%1 [R = 301,L]
 

请会有人指出我需要修改,​​以bin中的? (问号)的网址是什么?

修改

只注意到,由于应用由 anubhava 给出低于的robots.txt例如答案不能解决的.txt文件,但只显示网页。

的.htaccess如下: -

  RewriteEngine叙述上

的RewriteBase /
的RewriteCond%{THE_REQUEST}  S / +指数 .PHP ([^  S&安培] +)?[NC]
重写规则^%1? [R = 301,L]

重写规则^ sitemap.xml的$的index.php?路径=进/ google_sitemap [L]
重写规则^ googlebase.xml $的index.php?路径=进/ google_base [L]
重写规则^下载/(.*)/index.php?route=error/not_found [L]
的RewriteCond%{HTTP_HOST}!^ WWW 。
(。*)重写规则^ $ HTTP://www.% {HTTP_HOST} / $ 1 [R = 301,L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d

#POS1
?重写规则^([^ /] +)/ $的index.php $ 1 [L,QSA]<  - 

的RewriteCond%{REQUEST_URI} * !。(ICO | GIF | JPG | JPEG | PNG | JS | CSS)
重写规则^([^] *)的index.php?_route _ = $ 1 [L,QSA]

#POS2
 

如果我想补充的< - 在POS1线,robots.txt的URL返回一个404页没有发现错误。

.htaccess伪静态规则转换为IIS的URL重写规则方法

如果我想补充的< - 在POS2线,robots.txt的网址只显示首页

EDIT2

在此期间,我已经排除的robots.txt 从重写通过添加以下根据重写基地/ : -

 重写规则^ robots.txt的 -  [L]
 

解决方案

您可以使用此code:

  RewriteEngine叙述上

的RewriteCond%{THE_REQUEST}  S / +指数 .PHP ([^  S&安培] +)?[NC]
重写规则^%1? [R = 301,L]

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^([^ /] +)/ $的index.php?$ 1 [L,QSA]
 

Example URL's:-

www.domain.com/index.php?bob www.domain.com/index.php?jane www.domain.com/index.php?fred

Need rewriting like:-

www.domain.com/bob www.domain.com/jane www.domain.com/fred

Have tried with many variations now but the closest I can get to is:-

www.domain.com/?bob www.domain.com/?jane www.domain.com/?fred

The below in .htaccess achieves this...

RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s(.*)/index.php [NC]
RewriteRule ^ %1 [R=301,L]

Please could someone point out what I need to modify to bin the ? (question mark) in the URL?

Edit

Just noticed that since applying the answer given by anubhava below that robots.txt for example doesn't resolve to the .txt file but just displays the homepage.

.htaccess below:-

RewriteEngine On

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

RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#pos1
RewriteRule ^([^/]+)/?$ index.php?$1 [L,QSA] <--

RewriteCond %{REQUEST_URI} !.*.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

#pos2

If I add the <-- line in pos1, the robots.txt URL returns a 404 page not found error.

If I add the <-- line in pos2, the robots.txt URL just displays the homepage.

Edit2

In the meantime, I have excluded robots.txt from rewrites by adding the following under Rewrite Base /:-

RewriteRule ^robots.txt - [L]

解决方案

You can use this code:

RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?$1 [L,QSA]

 
精彩推荐
图片推荐