[英].htaccess-File to Control the Routing of a certain php file
I have a few php files in my server root directory https://example.com
.我的服务器根目录中有几个 php 文件
https://example.com
。
My current .htaccess
-file does:我当前的
.htaccess
-file 执行以下操作:
php
file ending)php
文件结尾)/index
to /
/index
重定向到/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1 [L,R=301]
Redirect 301 /index /
Let us now consider the following two:现在让我们考虑以下两个:
/cart.php
/checkout.php
The goal is:目标是:
https://example.com
/checkout
if the referrer is https://example.com
/cart
, else redirect to https://example.com
/cart
https://example.com
/cart
,则仅响应https://example.com
/checkout
,否则重定向到https://example.com
/cart
https://example.com
/checkout
to https://example.com
/cart/checkout
https://example.com
/checkout
重定向/重写到https://example.com
/cart/checkout
With your shown samples of urls and for your requested only this htaccess rules are, could you please try following.使用您显示的 url 示例以及您所要求的仅此 htaccess 规则,您能否尝试以下操作。
RewriteEngine ON
##First rule of getting response of checkout when cart is requested.
RewriteCond %{REQUEST_URI} ^/cart/?$ [NC]
RewriteRule ^(.*)/?$ /checkout [NC,L]
##Rewriting to /cart/checkout when checkout is requested.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} ^/checkout/?$ [NC]
RewriteRule ^(.*)$ /cart/checkout/? [R=301,NC,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.