htaccess 301 用于多个域和以空格命名的文件
我有一个客户,他运行着一组成功的网站,这些网站是用原始 html 构建的。他现在觉得应该将其数据库化。
我有两个问题,我想知道是否有一个正则表达式可以容纳它们。
我希望他的网站在一个位置运行但使用多个域。
他还用空格命名了所有文件。
举例来说...
我运行该网站 www.maindomain.com
有人进入 www.domain1.com/first Category.html
我想要 301 重定向到 www.domain1.com/categories/first-category
或有人进入 www.domain2.com/second Category.html
我想要 301 重定向到 www.domain2.com/catergories/second-category
这可以实现吗?我的客户有数千个这样的页面,所以我不想要一个带有单独 301 重定向的巨大 htaccess 文件
I have a client who runs a successful set of websites which he has built with raw html. He now feels it should be databased.
There are two issues I have and I was wondering if there is a regular expression to accommodate them both.
I want his website to run in the one location but use multiple domains.
Also he has named all his files with spaces.
So for example...
I run the site on
www.maindomain.com
Somebody enters on
www.domain1.com/first category.html
and I want a 301 redirect to
www.domain1.com/categories/first-category
or somebody enters on
www.domain2.com/second category.html
and I want a 301 redirect to
www.domain2.com/catergories/second-category
Is this achievable? My client has thousands of these pages so I dont want a huge htaccess file with individual 301 redirects
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 mod_rewrite,您将需要 2 组重写。首先将空格更改为内部重定向的破折号 (-):
这将循环直到没有更多空格,因此“www.domain1.com/first Category.html”在内部被重写为“www.domain1.com/first-”类别.html”。然后我们删除末尾的“.html”并在开头插入“/categories/”:
然后将内部“www.domain1.com/first-category.html”请求重定向(使用301)到“www.domain1.com/first-category.html”。 domain1.com/categories/first-category”。现在的问题是,“/categories/”与以“category.html”结尾的原始url有什么关系吗?如果是这样,那么您将需要一些额外的重写。
Using mod_rewrite, you'll need 2 sets of rewrites. First to change the spaces to dashes (-) that INTERNALLY redirect:
This will loop until there are no more spaces, so "www.domain1.com/first category.html" gets rewritten internally as "www.domain1.com/first-category.html". Then we remove the ".html" at the end and insert a "/categories/" in the beginning:
This then redirects (with 301) the internal "www.domain1.com/first-category.html" request to "www.domain1.com/categories/first-category". Now the question is, does the "/categories/" have anything to do with the original url ending with "category.html"? If so, then you're going to need some additional rewrites.