如何创造一个更美好的URL具有的.htaccess和多个参数? [英] How to make a better URL with .htaccess and multiple parameters?

查看:241
本文介绍了如何创造一个更美好的URL具有的.htaccess和多个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的一个不友好的URL的,我希望做SEO更好的网站:

I have a very long a unfriendly URL an I'm looking to make SEO better for the site:

http://www.site.com/子网站/ index.php页面= nameofpage和放大器;区域设置=的en_EN

我想,而不是有这样的: HTTP:// www.site.com/sub-site/en/nameofpage

I would like to have this instead: http:// www.site.com/sub-site/en/nameofpage

所有网址都难以codeD在形式的链接:

all the URLS are hard coded in the links in the form of:

<a href="index.php?page=nameofpage&locale=en_EN">link</a>

什么是与mod-rewrite来实现这一目标的最佳途径? 我觉得特别难以实现:

What is the best way to achieve this with mod-rewrite? I find it particularly difficult to achieve:

  • 在结合两个参数,页面, 语言环境
  • 谈到的en_EN为EN ISO语言环境中的网址
  • 我应该如何写链接?使用结果URL或的index.php?网页... 控制器方案?
  • combining both parameters, page and locale
  • Turning ISO locales EN_en to en in the URL
  • How should I write links? using the result URL or the index.php?page... controller scheme?

编辑: 我要疯了!我不能使它工作!觉得这么愚蠢......可是,谁能帮我确切的.htaccess文件我需要拉这一关?谢谢!

I'm going mad! I can't make it work!! Feel so stupid... but, Could anyone help me with the exact .htaccess file I need to pull this off? Thanks!

推荐答案

mod_rewrite的是一个非常复杂的野兽。这应该让你开始,但!刚读上的文档和玩它。你会得到它的坑很快!

mod_rewrite is an incredibly complex beast. This should get you started, though! Just read up on the documentation and play around with it. You'll get the hang of it soon enough!

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document. If this isn't true, it sends the
    # request to index.php
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/(.*)$ index.php?locale=$1&page=$2
    RewriteRule ^(.*)$      index.php?page=$1
</IfModule>

编辑:您应该复制并粘贴到一个的.htaccess 文件

这篇关于如何创造一个更美好的URL具有的.htaccess和多个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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