如何重写与的.htaccess [英] How to rewrite with .htaccess

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

问题描述

我是pretty的新的的.htaccess 并有一个问题。

I'm pretty new to .htaccess and have a question..

我将如何改写

http://example.com/forums/view.php?v=Topic%20Name&a=64 的http:// example.com/forums/view/Topic-Name/64

如前所述,我是新来的..

as stated above, I'm new to this..

另外,我怎么会替换 - ,同时保持正常的破折号?

Also, how would I replace - with   while keeping normal dashes?

示例:! 您好,再见然后将转换成的Hi-有再见

这会再转换回您好,再见! PHP和.htaccess

推荐答案

第一个问题是pretty的基础。你需要从丑(但工作),网址为搜索引擎优化的URL,并从搜索引擎优化的URL重写内部的丑陋的网址外部重定向。他们都可以写成以下格式:

The first question is pretty basic. You need an external redirect from the 'ugly' (but working) url to the seo url and an internal rewrite from the seo url to the 'ugly' url. They can all be written in the following format:

#External redirect
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /forums/view\.php\?v=([^&]+)&a=(.+)\ HTTP
RewriteRule ^ /forums/view/%1/%2 [R,L]
#Change above [R,L] to [R=301,L] after testing all rules work as expected

#Internal rewrite
RewriteRule ^forums/view/([^/]+)/([^/]+)/?$ /forums/view.php?v=$1&a=$2 [L]

第二件事情是不可能的。有没有办法有和 喜之间的仪表板和之间的破折号之间的区别再见。我会说:不要打扰。这是一个搜索引擎优化的URL。如果你想有看中搜索引擎优化的URL,你必须改变你的数据库中包含那些花哨的搜索引擎优化的URL。

The second thing is not possible. There is no way to distinguish between the dash between Hi and There and the dash between There and Bye. I would say: Don't bother. It's a seo-url. If you want to have fancy seo-url's, you'll have to alter your database to contain those fancy seo-urls.

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

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