URL 重写 - 初学者指南 [英] URL rewriting - Beginners guide

查看:35
本文介绍了URL 重写 - 初学者指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要学习如何为网站重写 URL 以获得漂亮的 URL...

I need to learn how to do URL rewriting for a site to get pretty URLs...

通过我阅读的 50 个教程,我对它的工作原理有了一个大致的了解.但他们都没有真正点击,也从未设法使其正常工作.

I have a general idea of how it works through the 50 tutorials I read. But none of them really clicked and never managed to make it properly work.

你知道有哪些适合我入门的教程吗?

这是我想如何使用它的示例:

Here is an example of how I want to use it:

这是基本链接http://www.dico2rue.com/dictionnaire.php?idW=675&word=Resto-basket

我希望它变成这样:http://www.dico2rue.com/dictionnaire/675/Resto-basket

但是当我这样做时,我的所有链接(例如 CSS 表、图像等)都不起作用.我是否需要完整链接(这显然会减慢您的网站速度)?

But when I did that, all my links (like for CSS sheets, images,...) didn't work. Do I need to full linking (which apparently slows your site down)?

感谢您的帮助.

UDPATE链接有 2 个选项

  • PAGE = ?page=1
  • WORD = ?idW=45&word=google-friendly-url-part-here

htaccess 中的代码是

The code in htaccess is

RewriteRule    ^dictionnaire.php/p([0-9]+)?$    dictionaire.php?page=$1    [NC,L]    
RewriteRule    ^dictionnaire.php/([0-9]+)/([a-z])?$    dictionaire.php?idW=$1&word=$2   [NC,L]

我希望这会有所帮助.

推荐答案

试试 CodeIgniter、Wordpress 或 Drupal 之类的东西.您可以看到 URL 是如何形成的,以及它们如何映射到 .htaccess 的内容.

Have a play with something like CodeIgniter, Wordpress, or Drupal. You can see how the URLs are formed and how they map to the contents of .htaccess.

这个 mod_rewrite 备忘单非常有用.

This mod_rewrite cheatsheet is very useful.

鉴于您的样式表已经被绝对引用(它们包括 http://www.dico2rue.com/) 这可能是因为您要让所有图像、样式表和 JavaScript 文件都通过 index.php.相反,您需要告诉 .htaccess 不理会物理文件,只解析其他 URL.

Given that your stylesheets are already referenced absolutely (they include http://www.dico2rue.com/) it's probably because you're telling all your images, stylesheets and JavaScript files to go through index.php. Instead you need to tell .htaccess to leave physical files alone, and only parse other URLs.

在这里发布您在 .htaccess 文件中的内容,我相信我们可以帮助修复它.

Post what you have in your .htaccess file here and I'm sure we can help fix it.

这篇关于URL 重写 - 初学者指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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