如何建立永久htaccess的 [英] How to create permalink in htaccess

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

问题描述

我要重定向一个链接到另一个在Linux主机.htaccess文件。你能帮助我吗?

 来源:http://example.com/examp
到:http://example.com/examp.php
 

和另一个用于我的其他网站

 来源:http://example.com/examp
到:http://example.com/user.php?u=examp
 

解决方案

您需要的的mod_rewrite 启用了这一点。开始有将这些进线的.htaccess:

  RewriteEngine叙述上
的RewriteBase /
 


TBH我不是100%肯定你是什么完全由永久含义及如何做你想做的重定向,所以我将提供2种型号的每个网址:重写(内部重定向)和重定向(301永久重定向)

1。这将重写(内部重定向)要求 http://example.com/examp http://example.com/examp.php ,而URL会留在浏览器中不变的:

 重写规则^ examp $ examp.php [L]
 

2。这将做同样如上但适当的重定向(301永久重定向)时,URL将在浏览器中改变:

 重写规则^ examp $ http://example.com/examp.php [R = 301,L]
 

3。这将重写(内部重定向)要求 http://example.com/examp http://example.com/user.php? U = examp ,而URL将在浏览器中保持不变:

 重写规则^ examp $ user.php的?U = examp [QSA,L]
 

4。这将做同样如上但适当的重定向(301永久重定向)时,URL将在浏览器中改变:

 重写规则^ examp $ http://example.com/user.php?u=examp [QSA,R = 301,L]
 

有用的链接: http://httpd.apache.org/docs/current/rewrite/

I want to redirect a link to another with .htaccess file in Linux host. Can you help me?

from: http://example.com/examp
to: http://example.com/examp.php

And another one for my other site

from: http://example.com/examp
to: http://example.com/user.php?u=examp

解决方案

You will need mod_rewrite enabled for this. Start with placing these lines into .htaccess:

RewriteEngine On
RewriteBase /


TBH I'm not 100% sure what do you mean exactly by permalink and how do you want to redirect, so I will provide 2 variants for each URL: rewrite (internal redirect) and redirect (301 Permanent Redirect).

1. This will rewrite (internal redirect) request for http://example.com/examp to http://example.com/examp.php while URL will remain unchanged in browser:

RewriteRule ^examp$ examp.php [L]

2. This will do the same as above but with proper redirect (301 Permanent Redirect) when URL will change in browser:

RewriteRule ^examp$ http://example.com/examp.php [R=301,L]

3. This will rewrite (internal redirect) request for http://example.com/examp to http://example.com/user.php?u=examp while URL will remain unchanged in browser:

RewriteRule ^examp$ user.php?u=examp [QSA,L]

4. This will do the same as above but with proper redirect (301 Permanent Redirect) when URL will change in browser:

RewriteRule ^examp$ http://example.com/user.php?u=examp [QSA,R=301,L]

Useful link: http://httpd.apache.org/docs/current/rewrite/

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

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