[英]Wordpress mod_rewrite
Think I read a bazillion articles over the past couple of days and yet I can still find out how to get mod-rewrites to work how I want. 想想我在过去几天阅读了大量的文章,但我仍然可以找到如何让mod-rewrites按照我想要的方式工作。 If you could help I would be forever grateful..
如果你能帮忙,我将永远感激..
I have a wordpress site, a category called cars, so using the Wordpress Permalinks it generates http://mysite.local/cars/ when I browse into that category. 我有一个wordpress网站,一个名为cars的类别,因此当我浏览该类别时,使用Wordpress永久链接生成http://mysite.local/cars/ 。 OK so far?
好的到目前为止?
I want to add a single post, lets call it car, so I can browse to http://mysite.local/cars/car/ and it displays my post. 我想添加一个帖子,让我们称之为汽车,所以我可以浏览到http://mysite.local/cars/car/并显示我的帖子。
But what I want to do is rewrite a list of manufacturers and append it to /cars/ but display http://mysite.local/cars/car/ 但我想要做的是重写制造商列表并将其附加到/ cars /但显示http://mysite.local/cars/car/
So for example: 例如:
The manufacturers are stored in an xml file which is changing, but I can deal with that bit later right? 制造商存储在一个正在改变的xml文件中,但我可以稍后处理这个问题吗?
Any suggestions, changes in approach gladly received. 任何建议,方法的变化都很高兴收到。
Stu 斯图
The Wordpress .htaccess file looks like this for reference: Wordpress .htaccess文件看起来像这样供参考:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
</IfModule>
# 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
I am so frustrated with this I'm about to create a script to physically create the directory structure I want.. which of course I dont want to do 我很沮丧,我即将创建一个脚本来物理创建我想要的目录结构..当然我不想这样做
You can't go on like this. 你不能这样下去。
If you do a rewrite, you need to conserve the variable. 如果进行重写,则需要保存变量。 Or else the server won't be able to know if you ask
http://mysite.local/cars/car/
for dodge, ford or anything else. 否则服务器将无法知道您是否要求
http://mysite.local/cars/car/
用于道奇,福特或其他任何内容。
What can be done is : 可以做的是:
RewriteRule ^cars/car/(.*)$ cars/car.php?model=$1 [L]
So that you just have one page called car.php
that handle your requests via a model
parameter. 因此,您只有一个名为
car.php
页面,它通过model
参数处理您的请求。 But I don't think it will suit you, since it's a reversal of the clean URL
paradigm. 但我认为它不适合你,因为它是
clean URL
范例的逆转。
Maybe you can use 也许你可以使用
RewriteRule ^cars/car/(.*)$ cars/car/ [E=MODEL:$1]
But the page addressed by cars/car/
will have to fetch the model value from the environments variables. 但是
cars/car/
寻址的页面必须从环境变量中获取模型值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.