我如何重写URL? [英] How do I rewrite the url?

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

问题描述

有人能告诉我如何重写这个URL。我已经看过了很多关于计算器的问题,但他们似乎缺少我的答案。

Could someone tell me how to rewrite this URL. I have looked at a lot of questions on stackoverflow but they seem to be missing my answer.

RewriteEngine On

这是我...它有点差。

That is what I have... its a bit poor.

我需要重写URL的,如果他们不指向一个目录。

I need to rewrite url's if they do not point to a directory.

我要做到这一点...

I need to do this...

any.domain.com/pages/some-page-slug/login

any.domain.com/pages/some-page-slug/login

要被改写的......正确的网址

To be rewritten to the correct url of...

any.domain.com/pages/login.php?page=32

any.domain.com/pages/login.php?page=32

没有人有任何想法如何能做到这一点?

Does anyone have any ideas on how this can be achieved?

推荐答案

1)重写product.php?ID = 12产品-12.html

1) Rewriting product.php?id=12 to product-12.html

这是一个简单的重定向中,PHP扩展是从浏览器的地址栏和动态URL(含?字符)隐藏转换成静态的URL。

It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing "?" character) is converted into a static URL.

RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1

2)重写product.php?ID = 12产品/ iPod的纳米/ 12.html

2) Rewriting product.php?id=12 to product/ipod-nano/12.html

SEO专家总是建议以显示URL中的主要关键字。在下面的URL重写技术,您可以显示URL中的产品的名称。

SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.

RewriteEngine on
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2

3)重定向非万维网网址WWW网址

3) Redirecting non www URL to www URL

如果您在浏览器中键入yahoo.com将被重定向到www.yahoo.com。如果你想要做同样与您的网站,然后把下面的code到.htaccess文件。这是什么样的重定向的好处?请查看搜索引擎友好的重定向(301)后重定向在PHP和.htaccess。

If you type yahoo.com in browser it will be redirected to www.yahoo.com. If you want to do same with your website then put the following code to .htaccess file. What is benefit of this kind of redirection?? Please check the post about SEO friendly redirect (301) redirect in php and .htaccess.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]

4)重写yoursite.com/user.php?username=xyz到yoursite.com/xyz~~V

4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz

你有没有在浏览器中选中zorpia.com.If键入 http://zorpia.com/roshanbh233 您可以看到我的个人资料在那里。如果你想要做同样的重定向,即 http://yoursite.com/xyz 来的 http://yoursite.com/user.php?username=xyz 那么你可以添加以下code到.htaccess文件。

Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1

5)重定向域里面的public_html一个新的子文件夹。

5) Redirecting the domain to a new subfolder of inside public_html.

假设你重建你的网站和所有的新的发展驻留内根的新文件夹folder.Then网站的新的发展能够像test.com/new,您里面。现在,将这些文件复制到根文件夹可以是一个忙碌的过程,以便您可以创建.htaccess文件里面以下code,并将其放置在网站的根文件夹。在结果www.test.com点出里面的新文件夹中的文件。

Suppose the you’ve redeveloped your site and all the new development reside inside the "new" folder of inside root folder.Then the new development of the website can be accessed like "test.com/new". Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it under the root folder of the website. In result, www.test.com point out to the files inside "new" folder.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1 

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

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