字preSS定制的mod_rewrite - totalnoob? [英] Wordpress custom mod_rewrite - totalnoob?

查看:164
本文介绍了字preSS定制的mod_rewrite - totalnoob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的字preSS安装一个定制的mod_rewrite规则,我已经有了一个自定义规则为我的网页结构,我想preserve。

I'm trying to make a custom mod_rewrite rule for my wordpress installation, I've already got a custom rule for my page structure which i would like to preserve.

新的自定义规则,我想提出的是,每当有像得到变量:www.mysite.com / 简介 = 用户名

The new custom rule i'd like to make is whenever there's a get variable like: www.mysite.com/?profile=username

我想使它看起来像:www.mysite.com/username

I want to make it look like: www.mysite.com/username

这是我目前的.htaccess文件:

This is my current .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

我看着php.net以及有关一般mod-rewrite很多教程,并专门为字preSS,但它的一切只是想直接在我的头上,我不明白。 如果任何人都可以给我一些帮助,以获得一些进展有了这个,我真的很AP preciate,我真的想要得到我的头周围的mod_rewrite。

I've looked at php.net and many tutorials about mod rewriting in general and specifically for wordpress, but its all just going straight over my head, I don't understand it. If anyone could give me some help to get some progress with this i'd really appreciate, i really want to get my head around mod_rewrite.

我假设我需要建立一个新的重写规则,但这是,据我得到的。

I'm assuming i need to create a new RewriteRule, but that's as far as i get.

谢谢 弗兰克

推荐答案

完成你想要完成的任务是困难的,至少可以这样说。它需要一个额外的PHP文件解析传入的请求,因为的.htaccess没有办法知道,如果该URL的用户名部分实际上是一个用户名或没有。

Accomplishing what you want to accomplish is difficult, to say the least. It requires an additional PHP file to parse incoming requests because .htaccess has no way to know if the USERNAME part of the URL is actually a username or not.

该PHP文件我提到将加载用户表从数据库和比较$ _GET ['个人资料']的项,并于比赛,重写/?轮廓= USERNAME

The PHP file I mention would load the users table from the database and compare $_GET['profile'] to the entries and, on match, rewrite to /?profile=USERNAME

如果没有匹配的,它只是传递到index.php文件。

If there's no match, it simply passes on to index.php.

不过,还有一个更简单的解决方案在这里,其中preserves很多你想要的:

However, there's a much easier solution here, which preserves a lot of what you want:

RewriteRule ^profile/([^/]+)$ ?profile=$1 [L]

这样做是重写从/型材/ 用户名导入/?配置= 用户名

What this does is rewrite from /profile/username to /?profile=username

这不正是你要找的,但它更容易实现。该规则应直接去下面重写规则^指数\ .PHP $ - [L] 在.htaccess文件

It's not exactly what you're looking for, but it's much easier to implement. The rule should go directly below RewriteRule ^index\.php$ - [L] in the .htaccess file.

如果您有任何问题,我很乐意解释一切都发生在这里。

If you have any questions, I'm more than happy to explain what all is happening here.

这篇关于字preSS定制的mod_rewrite - totalnoob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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