htaccess 正在工作,但不会替换 url

发布于 2025-01-14 03:10:32 字数 699 浏览 3 评论 0原文

我正在尝试修改 URL 中的子域名以使其看起来更好。我当前的 URL 看起来像这样:

www.mystore.com/productInfo.php?cPath=11_11&productID=222

因此,我想通过使用以下代码在 main 中的 .htaccess 中重写来使其更好:

RewriteEngine On    
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]

当我通过键入 www.mystore.com/productInfo/11_11/ 在 URL 上运行并测试它时222 在 URL 中效果很好。但是,当此页面被其他页面重定向或使用自重定向 a href= 链接“刷新”时(其中该链接是由以前的程序员用 php 编写的),上述旧链接在 URL 中仍然可见,而不是在新 URL 中可见。

我仍然是一个初学者,虽然我怀疑我可能需要为此更改 cPanel/Apache 中的某些内容(我认为),但目前,我仍然无法访问 cPanel 控件。是否有任何我可能错过在 .htaccess 文件中写入的内容,或者我确实需要 cPanel 控件或任何其他原因?

任何帮助表示赞赏。抱歉,我找不到与此相关的类似问题。

I'm trying to modify the subdomain name in the URL to make it look nicer. My current URL look something like:

www.mystore.com/productInfo.php?cPath=11_11&productID=222

So, I want to make it nicer by Rewrite in .htaccess in main with this code:

RewriteEngine On    
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]

When I run and test it on the URL by typing www.mystore.com/productInfo/11_11/222 in the URL it works well. However, when this page is redirected by a different page or is 'refreshed' with a self redirecting a href= link(in which the link is written in php by the previous programmer), the above old link is still visible in the URL instead of the new one.

I am still a beginner while I suspect that I might need to change something in the cPanel/Apache(I think) for this but currently, I am still do not have access to the cPanel control. Is there anything that I might have missed to write in the .htaccess file or I really do need the cPanel control or any other reasons?

Any help is appreciated. Sorry that I could not find similar questions on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住你手 2025-01-21 03:10:32

您可以使用以下内容:

RewriteEngine On
RewriteBase /

#redirect /productInfo.php?cPath=foo&productID=bar to /productInfo/foo/bar
RewriteCond %{THE_REQUEST} /productInfo\.php\?cPath=([0-9_-]+)&productID=([0-9_-]) [NC]
RewriteRule ^ productInfo/%1/%2? [L,R=301]
#rewrite new URL to the old one
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]

You can use the following :

RewriteEngine On
RewriteBase /

#redirect /productInfo.php?cPath=foo&productID=bar to /productInfo/foo/bar
RewriteCond %{THE_REQUEST} /productInfo\.php\?cPath=([0-9_-]+)&productID=([0-9_-]) [NC]
RewriteRule ^ productInfo/%1/%2? [L,R=301]
#rewrite new URL to the old one
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文