【问题标题】:Rewrite URL with subdirectory and file用子目录和文件重写 URL
【发布时间】:2013-11-20 19:20:25
【问题描述】:

我正在尝试使用 .htaccess 重写我网站的 URL,这就是我想要的

目前,网址如下所示

http://www.mysite.biz/store/cart.php?m=new_arrivals

所有网站都是使用 php GET 加载的,唯一改变的是 cart.php 之后的查询字符串,所以我想重写为....

http://www.mysite.biz/cart.php?m=new_arrivals

我一直在互联网上进行搜索,并尝试了各种技术来做到这一点,但都没有奏效。这个我试过了...

RewriteRule ^store/(.*)$ http://www.mysite.biz/$1 [R=301,L]

这...

RewriteCond %{REQUEST_URI} ^/store($|/)
RewriteRule ^.*$ /store/cart.php [L]

还有这个……

RewriteCond $1 !^store
RewriteRule ^(.*) /store/$1 [L] 

我已经开发网络一段时间了,但这是我第一次真正用 .htaccess 做任何事情,我完全被难住了。任何帮助将不胜感激

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    在您的 DOCUMENT_ROOT/.htaccess 文件中尝试此规则:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+store/(cart\.php[^\s]+) [NC]
    RewriteRule ^ /%1 [R=302,L]
    
    RewriteRule ^(cart\.php)$ /store/$1 [L,NC]
    

    【讨论】:

    • 好的,我刚试过,但没有用。我在 .htaccess 中有一些其他的东西,但我把所有东西都注释掉了,除了你的线,它仍然没有工作......
    • 您是否期望从http://www.mysite.biz/store/cart.php?m=new_arrivalshttp://www.mysite.biz/cart.php?m=new_arrivals 的外部重定向?
    • 我将您的代码添加到我的 .htaccess 文件中,我将其 ftp 到我网站的根目录,然后我转到我网站上的不同页面。 /store/cart.php 保留在您提供的两段代码的 url 中
    • 您确定.htaccess 和mod_rewrite 已启用?
    • 是的,我还有其他重写规则,它们工作正常。我在测试时将它们注释掉了,它仍然没有工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 2020-01-08
    • 2015-02-06
    相关资源
    最近更新 更多