开发者

Wordpress mod_rewrite

开发者 https://www.devze.com 2023-03-13 22:38 出处:网络
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.If you could help I would be forever grateful..

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. 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. 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.

But what I want to do is rewrite a list of manufacturers and append it to /cars/ but display http://mysite.local/cars/car/

So开发者_JAVA技巧 for example:

  • http://mysite.local/cars/dodge/ == http://mysite.local/cars/car/
  • http://mysite.local/cars/ford/ == http://mysite.local/cars/car/
  • http://mysite.local/cars/bmw/ == http://mysite.local/cars/car/

The manufacturers are stored in an xml file which is changing, but I can deal with that bit later right?

Any suggestions, changes in approach gladly received.

Stu

The Wordpress .htaccess file looks like this for reference:

<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.

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. But I don't think it will suit you, since it's a reversal of the clean URL paradigm.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消