htaccess url 从请求查询重写到文件夹,并更改 php 名称
htaccess url rewriting from request query to folder like and changing the php name
如何在稍后在线托管的本地主机上执行以下操作:
我有这个link:
http://localhost/shops/shop.php?c=15
我想改写成http://localhost/shops/shop/15
htaccess 是(放在C:\wamp\www\shops folder
):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?RECIPES/(.*?)/?$ /single-product-details.php?= [L]
RewriteRule ^/?SHOP/(.*?)/?$ /shop.php?= [L]
使用您展示的示例,请尝试遵循以下规则。将您的 htaccess 文件与 shops 文件夹一起放置(不在其中)。
请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine ON
RewriteBase /shops/
##External redirect to friendly url.
RewriteCond %{THE_REQUEST} \s/shops/(shop)\.php\?c=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite to actual url/files.
RewriteRule ^([^/]*)/(.*)/? .php?c= [QSA,L]
如何在稍后在线托管的本地主机上执行以下操作:
我有这个link:
http://localhost/shops/shop.php?c=15
我想改写成http://localhost/shops/shop/15
htaccess 是(放在C:\wamp\www\shops folder
):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?RECIPES/(.*?)/?$ /single-product-details.php?= [L]
RewriteRule ^/?SHOP/(.*?)/?$ /shop.php?= [L]
使用您展示的示例,请尝试遵循以下规则。将您的 htaccess 文件与 shops 文件夹一起放置(不在其中)。
请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine ON
RewriteBase /shops/
##External redirect to friendly url.
RewriteCond %{THE_REQUEST} \s/shops/(shop)\.php\?c=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite to actual url/files.
RewriteRule ^([^/]*)/(.*)/? .php?c= [QSA,L]