mod_rewrite到text/type/id [英] mod_rewrite to text/type/id

查看:75
本文介绍了mod_rewrite到text/type/id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的代码是这样的

store.php?storeid=12&page=3

我正在寻找将其翻译成这样的东西

and I'm looking to translate it to something like this

mysite.com/roberts-clothing-store/store/12/3

以及类似的内容:

profile.php?userid=19

mysite.com/robert-ashcroft/user/19

我了解最好是将SEO友好文本尽可能地向左移,即

I understand that it's best to have the SEO-friendly text as far left as possible, ie not

mysite.com/user/19/robert-ashcroft

(stackoverflow做什么)

(what stackoverflow does)

我无法在apache的mod_rewrite中弄清楚该怎么做.

I can't figure out how to do this in apache's mod_rewrite.

推荐答案

实际上,您可能不得不将mod_rewrite视为颠倒".

Actually, you may have to think "upside-down" with mod_rewrite.

最简单的方法是使您的 PHP发出重写的 mysite.com/roberts-clothing-store/store/12/3 链接.

The easiest way is that to make your PHP emit the rewritten mysite.com/roberts-clothing-store/store/12/3 links.

mod_rewrite 将请求代理一个PHP页面,以rewrite.php?path=roberts-clothing-store/store/12/3 解码URL strong>并设置参数(此处为storeidpage) 并且动态地包含正确的 PHP文件,只需为重命名的页面发出 301

mod_rewrite will then proxy the request to one PHP page for rewrite.php?path=roberts-clothing-store/store/12/3 that will decode the URL and sets the arguments (here storeid and page) and dynamically include the correct PHP file, or just emit 301 for renamed pages.

使用mod_rewrite的纯解决方案是可能的,但是这个解决方案更容易,尤其是在您不掌握mod_rewrite的情况下.

A pure solution with mod_rewrite is possible, but this one is much easier to get right, especially when you don't master mod_rewrite.

主要概率可能与开销一起使用,但这可能很重要,但其代价是简单性和易用性.灵活性. mod_rewrite快很多

The main prob could be with the overhead that might be significant but is the price of simplicity & flexibility. mod_rewrite is much faster

其他帖子确实回答了这个问题,但是他们并没有解决典型的重​​复内容问题,而该问题可以通过使用规范的url(并使用301/404表示所有看起来不错的URL来避免,但不是).

The other posts do answer the question, but they don't solve the typical duplicate-content problem that avoided by having canonical urls (and using 301/404 for all those URLs that seems ok, but aren't).

这篇关于mod_rewrite到text/type/id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆