简体   繁体   中英

.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 .

My current .htaccess -file does:

  • rewriting (removing the php file ending)
  • redirect from /index to /
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:

  • only response https://example.com /checkout if the referrer is https://example.com /cart , else redirect to https://example.com /cart
  • redirect/rewrite from https://example.com /checkout to 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.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM