首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GoDaddy上的Wordpress URL参数

GoDaddy上的Wordpress URL参数
EN

Stack Overflow用户
提问于 2011-11-11 13:27:24
回答 1查看 267关注 0票数 1

我目前正在制作一个网站(http://tannernelson.me/ehs)

它托管在Godaddy上,我正在使用wordpress作为CMS。

我希望能够做到:

代码语言:javascript
复制
http://tannernelson.me/ehs/school/academics/teachers/jsmith

变成

代码语言:javascript
复制
http://tannernelson.me/ehs/index.php?pagename=teachers&detail=jsmith

因此,基本上,如果url有4个段(学校/学者/教师/jsmith),我希望最后一个段是一个变量。因此,任何url的第四段都将是变量"detail“。

我当前的URL重写是

代码语言:javascript
复制
# Mod Rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ehs/index.php [L]
Options -Multiviews

它不会以任何其他方式工作,即使使用默认的WordPress .htaccess文件。我不知道这是什么意思,也不知道它是什么类型的请求URI。这真的很让人困惑。

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-11 21:31:22

您现在拥有的代码意味着:

代码语言:javascript
复制
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

如果请求的文件名不是 (!)常规文件-f,并且如果请求的文件名不是 (!)目录-d,则:

代码语言:javascript
复制
RewriteRule . /ehs/index.php [L]

匹配任何单个字符(.),如果找到匹配,则将URL重写为/ehs/index.php,然后将其作为最后一个规则([L]),因此不再处理任何其他规则。

这看起来不像你想要的,但似乎起作用了。http://tannernelson.me/ehs/school/academics/teachers/jsmith提供(我认为) http://tannernelson.me/ehs/index.php,因为我得到了一个自定义的404not found页面。

尝试以下.htaccess代码:

代码语言:javascript
复制
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

# Redirect the ehs/school/academics/$1/$2 URIs to /ehs/index.php?pagename=$1&detail=$2
RewriteRule ^ehs/school/academics/([^/]+)/([^/]+)$ /ehs/index.php?pagename=$1&detail=$2 [L]

# Otherwise if the requested URI is not found (not a file nor a directory)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#Redirect everything else to index.php
RewriteRule .* /ehs/index.php [L]

Options -Multiviews

我刚刚在我的Apache服务器上测试了它,它工作正常。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8090041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档