忽略.htaccess中URI的子文件夹
我有一个应用程序,您可以在其中发送链接到内容。链接是这样的:domain.com/share/param1/param2/param3
如果用户安装了应用程序,则打开该应用程序,否则它将打开网站。对于那些未安装的应用程序的人,我在domain.com/share.com/share
上获得了一个网页,放置了下载应用程序的链接。问题是,如果您致电/share /.../.../...您不会重定向到
/share
。
我想用/share /... 开始将所有
重定向
内容
RewriteEnginge On
#1
RewriteRule ^share/.*$ share
#2
RewriteRule ^share/(.*)$ share
#3
RewriteRule ^share\/(.*)$ share
#4
RewriteRule share/.* share
#5 this is to exclude an error to Regex
RewriteRule share/test share
。 htaccess (希望)没有影响:
# BEGIN Thunermay (Admin)
# set apple-app-site-association as application/json for Apple's crawler
<Files "apple-app-site-association">
Header set Content-type 'application/json'
</Files>
# ensure https
RewriteEngine On
# redirect all /share/anything links to /share
# Here was I trying to get it to work #
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
# END Thunermay
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
谢谢!
I have an app where you can send a link to content. The link is build like this:domain.com/share/param1/param2/param3
The app is opened if the user has the app installed, otherwise it will open the website. For those who have not the app installed I got a webpage at domain.com/share
where links to download the app are placed. The problem is that if you call / share/.../.../...
you don't get redirected to /share
.
I want to redirect everything with /share/...
beginning to /share
I'm running Wordpress on an Apache
What I tried:
RewriteEnginge On
#1
RewriteRule ^share/.*$ share
#2
RewriteRule ^share/(.*)$ share
#3
RewriteRule ^share\/(.*)$ share
#4
RewriteRule share/.* share
#5 this is to exclude an error to Regex
RewriteRule share/test share
The rest of the .htaccess
which (hopefully) doesn't have an impact:
# BEGIN Thunermay (Admin)
# set apple-app-site-association as application/json for Apple's crawler
<Files "apple-app-site-association">
Header set Content-type 'application/json'
</Files>
# ensure https
RewriteEngine On
# redirect all /share/anything links to /share
# Here was I trying to get it to work #
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
# END Thunermay
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如@cbroe所说,问题是我没有重定向到页面,而只会在内部重定向,即问题所在,而该站点不存在。解决方案是:
重写/share/.+共享[r,l]
+
至少具有一个字符,因为否则它以无限循环结束,r
是重定向,不仅将其显示在URI和l 是因为它是最后一个规则,WordPress不会捕获它,并指向着陆页。
剩下的一些问题是,如果我的https重定向不再起作用,如果我有共享链接并使用
http
我的URI-Generator不可能,所以它不应该是一个问题。The problem was, as @Cbroe stated, that I didn't redirect to the page but would only internally redirect, where the problem is, that this site does not exist. The solution was:
RewriteRule /share/.+ share [R,L]
The
+
is to have at least one character because otherwise it ended in an infinite loop, theR
is to redirect it and not only show it in the URI and theL
is for that it is the last rule and Wordpress does not catch it and point to the landing page.The slight problem remaining is that my https redirect does not work anymore IF I have a share link and use
http
which my URI-generator does not, so it should not be an problem.