我目前正在制作一个网站(http://tannernelson.me/ehs)
它托管在Godaddy上,我正在使用wordpress作为CMS。
我希望能够做到:
http://tannernelson.me/ehs/school/academics/teachers/jsmith变成
http://tannernelson.me/ehs/index.php?pagename=teachers&detail=jsmith因此,基本上,如果url有4个段(学校/学者/教师/jsmith),我希望最后一个段是一个变量。因此,任何url的第四段都将是变量"detail“。
我当前的URL重写是
# 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。这真的很让人困惑。
有什么想法吗?
发布于 2011-11-11 21:31:22
您现在拥有的代码意味着:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d如果请求的文件名不是 (!)常规文件-f,并且如果请求的文件名不是 (!)目录-d,则:
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代码:
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服务器上测试了它,它工作正常。
https://stackoverflow.com/questions/8090041
复制相似问题