htaccess重写规则以删除某些子文件夹中的问号

时间:2018-12-03 22:18:13

标签: .htaccess redirect mod-rewrite

当前,我的网站使用以下URL进行工作:

  

https://www.example.com/post/?some-post-message

     

https://www.example.com/home/?form-info

     

https://www.example.com/build/?how-to-build-3

我想从URL中删除问号,即。 .htaccess重写,因此当请求以下URL时,将从服务器显示以上页面:

  

https://www.example.com/post/some-post-message

     

https://www.example.com/home/form-info/

     

https://www.example.com/build/how-to-build-3

当地址栏中不存在问号时,我需要浏览器显示带有问号的页面。我还有其他页面使用吗?我想不受影响,即:https://www.example.com/a=122&b=34223555&c=87sd78s7 https://www.example.com/post/send.php?messagesinfo (和其他网址)

这是我当前放在一起的.htaccess文件,该文件不起作用:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
ErrorDocument 404 /404.php

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ post/(index\.php)?\?([^&\ ]+)
RewriteRule ^ post/%1? [L,R=301]

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ home/(index\.php)?\?([^&\ ]+)
RewriteRule ^ home/%1? [L,R=301]

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ build/(index\.php)?\?([^&\ ]+)
RewriteRule ^ build/%1? [L,R=301]

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

0 个答案:

没有答案