我有laravel网站,并且有包含wordpress博客的博客文件夹。在我的htaccess中,我想要一些允许在家中打开否则重定向的路径。所以我的帖子预览链接也在主页上重定向。我想阻止它。预览链接就像https://www.test.com/?p=16286。我想重定向特定页面。下面是我的htaccess代码
RewriteEngine on
RewriteCond %{REQUEST_URI} !/my-form
RewriteCond %{REQUEST_URI} !/save_subscribe_user
RewriteCond %{REQUEST_URI} !/demo
RewriteCond %{REQUEST_URI} !/xamarin-app-development
RewriteCond %{REQUEST_URI} !/xamarin-app-development-inner
RewriteCond %{REQUEST_URI} !/web-and-mobile-app-development
RewriteCond $1 !^(blog|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ blog/$1 [L,QSA]
## EXPIRES CACHING ##
<FilesMatch "\.(js)$">
AddHandler application/x-httpd-php .js
</FilesMatch>
## EXPIRES CACHING ##
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
#This line added to allow blog in URL and allow routing through Laravel
RewriteCond %{REQUEST_URI} !^/blog/
#Blog post preview URL
RewriteCond %{QUERY_STRING} ^p=([0-9]*)
RewriteRule ^ http://www.test.com/?p=%1&preview=true [R=301,L]
</IfModule>
这两行:
RewriteCond %{QUERY_STRING} ^p=([0-9]*)
RewriteRule ^ http://www.test.com/?p=%1&preview=true [R=301,L]
查询字符串以数值作为你需要重定向的目标开始,所以它会被越来越多地重写,你可能会更加具体,就像你在quistion中所做的那样,将$
添加到^p=([0-9]*)$
以便从新版本中加入。像这样改变你的规则:
RewriteCond %{QUERY_STRING} ^p=([0-9]*)$
RewriteRule ^ http://www.test.com/?p=%1&preview=true [R=301,L]
如果不行,并且您需要在任何重写规则之前匹配此查询字符串,只需在该特定步骤之前将其放置。
注意:清除浏览器缓存然后测试