如何制作干净的URL [英] How to make Clean URLs

查看:182
本文介绍了如何制作干净的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,当我显示任何页面时,URL都会更改为: https://www.asdgsdgsd.nl/index.php 或about.php或contact.php等等...

I have a website, and when i display any page the url will change to: https://www.asdgsdgsd.nl/index.php or about.php or contact.php etc...

我已经看到您可以使用.htaccess创建清洁网址",但是其中的链接为:

I have seen that you can create 'Clean urls' with .htaccess, but there the links were: https://www.asdgsdgsd.nl/index.php?page=$1.

我可以创建干净的网址吗?

is it possible for me to create clean urls?

我已经在根文件夹的.htaccess文档中尝试过此操作:

i have tried this in a .htaccess document on my root folder:

    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9]+)$ index.php

请一些可以帮助我的人?​​? 您需要更多信息吗?只是问问,我会回答的!!

Some one who can help me please?? you need some more information? just ask and i wil answer it!!

推荐答案

您已经通过使用重写规则有了主意,但是您错过了最后一点.

You have the idea by using the rewrite rule, but you have missed out of the last bit.

RewriteRule ^([a-zA-Z0-9]+)$ index.php?id=$1

$1将采用输入的第一个变量,因此您可以使用/index/example,并且可以将示例字词提取为_get['id']

The $1 will take the first varable entered so you can have /index/example and the word example can be pulled as a _get['id']

您可以通过以下方式创建多胞胎:

You can create multipule in this way:

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ index.php?id=$1&login=$2

以此类推.

更新:

如果您只是想让URL看起来更好,请点击此链接,并阅读使用重写规则的所有不同方式.

If you just want to make the URL look nicer follow this link and read up on all the different ways of using the rewrite rule.

您可以更改http://www.pets.com/pet_care_info_07_07_2008.php

要看起来像这样:http://www.pets.com/pet-care/

如果这就是您要寻找的,那么您要使用的规则是:

If thats what you are looking for then the rule you want to use is:

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^pet-care/?$    pet_care_info_01_02_2008.php    [NC,L]    # Handle requests for "pet-care"

引自https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/

魔术发生的地方是"RewriteRule"行.该行可以分为5部分:

The "RewriteRule" line is where the magic happens. The line can be broken down into 5 parts:

RewriteRule-告诉Apache这就像是指一个RewriteRule.

RewriteRule - Tells Apache that this like refers to a single RewriteRule.

^/pet-care/?$-样式".服务器将检查对站点的每个请求的URL,以查看此模式是否匹配.如果是这样,那么Apache会将请求的URL交换为随后的替换"部分.

^/pet-care/?$ - The "pattern". The server will check the URL of every request to the site to see if this pattern matches. If it does, then Apache will swap the URL of the request for the "substitution" section that follows.

pet_care_info_01_02_2003.php-替代".如果上面的模式与请求匹配,则Apache使用该URL而不是请求的URL.

pet_care_info_01_02_2003.php - The "substitution". If the pattern above matches the request, Apache uses this URL instead of the requested URL.

[NC,L]-标记",告诉Apache如何应用规则.在这种情况下,我们使用两个标志. "NC"告诉Apache该规则不区分大小写,"L"告诉Apache如果使用此规则,则不再处理任何规则.

[NC,L] - "Flags", that tell Apache how to apply the rule. In this case, we're using two flags. "NC", tells Apache that this rule should be case-insensitive, and "L" tells Apache not to process any more rules if this one is used.

#处理宠物照管"的请求-注释说明该规则的作用(可选,但建议)

# Handle requests for "pet-care" - Comment explaining what the rule does (optional but recommended)

这篇关于如何制作干净的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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