Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess detect“/“已登录”;在任何URL的末尾,并重定向到同一URL_.htaccess_Url Rewriting - Fatal编程技术网

.htaccess detect“/“已登录”;在任何URL的末尾,并重定向到同一URL

.htaccess detect“/“已登录”;在任何URL的末尾,并重定向到同一URL,.htaccess,url-rewriting,.htaccess,Url Rewriting,我想知道如何创建一个.htaccess重写规则,该规则可以在任何漂亮URL的末尾检查“/登录”,然后将GET参数传递回该页面 基本上,用户可以登录任何页面,然后该页面会重新加载,并附加/登录到该页面。我需要运行一些PHP来检查: if ($_GET['mode'] == 'logged-in') 要在页面上显示模式,他们需要确认登录 它可以是网站上的任何页面,任何深度 因此,示例URL可能是: www.domain.com/shop/category-id/logged-in 需要重写为:

我想知道如何创建一个.htaccess重写规则,该规则可以在任何漂亮URL的末尾检查“/登录”,然后将GET参数传递回该页面

基本上,用户可以登录任何页面,然后该页面会重新加载,并附加/登录到该页面。我需要运行一些PHP来检查:

if ($_GET['mode'] == 'logged-in') 
要在页面上显示模式,他们需要确认登录

它可以是网站上的任何页面,任何深度

因此,示例URL可能是:

www.domain.com/shop/category-id/logged-in
需要重写为:

www.domain.com/shop/category-id/?mode=logged-in
显然,上述URL在此之前已被重写,因为它实际上正在加载:

www.domain.com/shop/category.php?id=category-id
因此,基本上需要知道如何检测:

*/logged-in 
然后回到

*/?mode=logged-in
同时保持URL的美观

以下是当前的重写规则。所有这些都需要在它们的末尾支持放置/登录,我希望我不必为每一个都手动制定新的重写规则

# BLOG
RewriteRule ^blog/page/([0-9]+)/?$    blog.php?page=$1     [NC,L]
RewriteRule ^blog/([A-Za-z0-9-_]+)/?$    blog.php?cat=$1    [NC,L]
RewriteRule ^blog/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$    blog-post.php?cat=$1&url=$2    [NC,L]

# SHOP API
RewriteRule ^shop/cart/add/([0-9]+)/([0-9]+)?/?$    shop/?mode=add2cart&id=$1&sku=$2    [NC,L]
RewriteRule ^shop/cart/update/([0-9]+)/([0-9]+)/([0-9]+)/?$    shop/?mode=updatecartitemcount&id=$1&sku=$2&count=$3    [NC,L]
RewriteRule ^shop/cart/remove/([0-9]+)/([0-9]+)/?$    shop/?mode=updatecartitemcount&id=$1&sku=$2&count=0    [NC,L]
RewriteRule ^shop/(generate_token)/?$    shop/?mode=$1   [NC,L]    
RewriteRule ^shop/(get_details)/([0-9]+)/?$    shop/?mode=$1&id=$2    [NC,L]

# SHOP
RewriteRule ^shop/([A-Za-z0-9-_]+)/?$    shop/category.php?cat=$1    [NC,L,QSA]
RewriteRule ^shop/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$    shop/category.php?cat=$1&subcat=$2    [NC,L,QSA]
RewriteRule ^shop/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([0-9-_]+)?/?$    shop/product.php?cat=$1&url=$2&id=$3    [NC,L,QSA]
RewriteRule ^policies/([A-Za-z0-9-_]+)/?$    policy.php?url=$1    [NC,L]

# CHECKOUT
RewriteRule ^checkout/(review)?/?$    checkout/index.php?view=review    [NC,L]
RewriteRule ^checkout/(checkout|payment|complete)/?$    checkout/index.php?view=$1    [NC,L]
RewriteRule ^checkout/load/([A-Za-z0-9-_]+)/?$    checkout/index.php?mode=load_content&view=$1    [NC,L]
RewriteRule ^checkout/(redeem_coupon|get_total|generate_token)/?$    checkout/index.php?mode=$1    [NC,L]
RewriteRule ^checkout/update_shipping/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$     checkout/index.php?mode=update_shipping&view=$1&country=$2&shipping_type=$3    [NC,L]

# USER ACCOUNTS
RewriteRule ^account/order/([0-9-_]+)/?$    view-order.php?id=$1    [NC,L]
RewriteRule ^account/order/([0-9-_]+)/print-invoice/?$    view-order.php?id=$1&mode=print-invoice    [NC,L]
RewriteRule ^account/update/([A-Za-z0-9-_]+)/?$    account.php?mode=update&section=$1    [NC,L]
RewriteRule ^forgot-my-password/submit/?$    forgot-my-password.php?mode=submit    [NC,L]
RewriteRule ^update-password/([A-Za-z0-9-_]+)/?$    forgot-my-password.php?hash=$1    [NC,L]
RewriteRule ^update-password/([A-Za-z0-9-_]+)/submit/?$    forgot-my-password.php?mode=reset-password&hash=$1    [NC,L]
RewriteRule ^register/submit/?$    index.php?mode=register    [NC,L]
RewriteRule ^login/submit/?$    index.php?mode=login    [NC,L]
RewriteRule ^logout/?$    index.php?mode=logout     [NC,L]
RewriteRule ^logged-out/?$    index.php?mode=logged-out    [NC,L]
RewriteRule ^subscribe/?$    index.php?mode=newsletter-subscribe    [NC,L]
RewriteRule ^confirm/([A-Za-z0-9-_]+)/?$    index.php?mode=newsletter-confirm&code=$1    [NC,L]
RewriteRule ^confirm-account/([A-Za-z0-9-_]+)/?$    index.php?mode=account-confirm&code=$1    [NC,L]
RewriteRule ^contact/submit/?$     contact.php?mode=submit    [NC,L]

# SEARCH RESULTS
RewriteRule ^search/?([A-Za-z0-9-_+]+)?/?$    search-results.php?query=$1    [NC,L]
RewriteRule ^search/([A-Za-z0-9-_+]+)/(render_results)/?$    search-results.php?query=$1&mode=$2     [NC,L]

Scott

您可以在
行的
重写引擎下方使用此规则:

RewriteEngine On

RewriteRule ^(.+)/(logged-in)/?$ $1?mode=$2 [L,QSA,NC]

# all your rules go below this line

我实际上还没有一个.htaccess规则,所以我想知道怎么做!现在完成了。我已经添加了为这个站点提供动力的所有规则。