Mod_rewrite 规则 - 删除文件夹名称

发布于 2025-01-02 11:20:57 字数 626 浏览 1 评论 0原文

我应该更改 URL 以获得 seo 排名。客户向我发送了新网址列表(30 项)。我是 mod_rewrite 新手,但今天我开始阅读手册

客户端 -> 服务器端

site.com/our-solutions/business.php -> site.com/content/solution/bc.php site.com/our-solutions/internal.php -> site.com/content/solution/ia.php site.com/our-solutions/assess-risk.php -> site.com/content/why/assess.php site.com/our-solutions/erm-risk.php -> site.com/content/why/model.php

等等,

你能帮我写一下这个案例的规则吗?我已经预定义了 URL 列表,但您可以看到我必须从每个 URL 中删除文件夹内容并将页面名称更改为所需的

I should change URLs to gain ranking on seo. Customer sent me the list of new urls(30 items). Im noobie in mod_rewrite, but today I began to read manuals

Client side -> server side

site.com/our-solutions/business.php -> site.com/content/solution/bc.php
site.com/our-solutions/internal.php -> site.com/content/solution/ia.php
site.com/our-solutions/assess-risk.php -> site.com/content/why/assess.php
site.com/our-solutions/erm-risk.php -> site.com/content/why/model.php

Etc.

could you helo me write the rules for this case? I have predefined list of urls but you can see I must to remove folder content from each URL and change the page name to desirable

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

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

发布评论

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

评论(1

寄风 2025-01-09 11:20:57

开头应该是这样的:

RewriteRule /our-solutions/business.php /content/solution/bc.php [NC,QSA,L]
RewriteRule /our-solutions/internal.php /content/solution/ia.php [NC,QSA,L]
RewriteRule /our-solutions/assess-risk.php /content/why/assess.php [NC,QSA,L]
RewriteRule /our-solutions/erm-risk.php /content/why/model.php [NC,QSA,L]

我很抱歉,但你的问题听起来很像“我不是很好,所以有人可以帮我做这份工作吗?”。我的意思是,只要环顾四周,你就会得到很多答案,只要你亲自动手。


如果这还不够:

两个提示:

如果您不在托管环境中(= 如果它是您自己的服务器并且可以修改虚拟主机,不仅仅是.htaccess文件),尝试使用RewriteLog指令:它可以帮助你追踪此类问题:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

我最喜欢的检查正则表达式的工具:

http://www.quanetic.com/Regex (不要忘记选择ereg(POSIX) 而不是 preg(PCRE)!)

Here's what the beginning should look like:

RewriteRule /our-solutions/business.php /content/solution/bc.php [NC,QSA,L]
RewriteRule /our-solutions/internal.php /content/solution/ia.php [NC,QSA,L]
RewriteRule /our-solutions/assess-risk.php /content/why/assess.php [NC,QSA,L]
RewriteRule /our-solutions/erm-risk.php /content/why/model.php [NC,QSA,L]

I'm sorry but your question sound very like "I'm not very good, so can someone do the job for me?". I mean, just look around, you'll get a lot of answer, just get your hands dirty.


And if that's not enough:

Two hints:

If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the .htaccess files), try to use the RewriteLog directive: it helps you to track down such problems:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

My favorite tool to check for regexp:

http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文