我想知道如何创建.htaccess重写规则,该规则可以在任何漂亮的URL的末尾检查“ / login-in”,然后将GET参数传递回该页面。
基本上,用户可以在任何页面上登录,然后重新加载该页面并附带/ logged-in。我需要运行一些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
在保持网址美观的同时
这是当前的重写规则。所有这些都还需要支持在其末尾放置/ login-in,我希望我不必为每个规则手动制定新的重写规则。
# 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§ion=$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]
斯科特
答案 0 :(得分:0)
您可以在RewriteEngine On
行下面使用此规则:
RewriteEngine On
RewriteRule ^(.+)/(logged-in)/?$ $1?mode=$2 [L,QSA,NC]
# all your rules go below this line