开发者

.htaccess problem, need to add string to certain URL's

In my infinity stupidity I changed the permalinks on my wordpress blog a little while back and have now changed them again. The problem that I have now caused is that I have a few hundred URL's out there which no longer work.

For example this URL looks like the ones that used to work

http://www.lazygamer.net/the-evopoints-co-za-downloads-of-the-week-1305/

But you'll see that just gives you a 404 not found page now because my site expects the first subdirectory to be a category such as

http://www.lazygamer.net/xbox-360/the-evopoints-co-za-downloads-of-the-we开发者_开发知识库ek-1305/

So now I want to put a htaccess rule in that checks to see if a category exists and if it doesn't then just add in something random to make the url resolve.

I'm pretty sure I can do this with a regular expression of sorts but I can't figure it out.

[Update] My current .htaccess file

RewriteEngine On
RewriteBase /
RewriteRule ^/([^/]+)/$ /category/$1/ [R]
RewriteRule ^index\.php$ - [L]
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www.lazygamer\.co.za$ [NC]
RewriteRule ^(.*)$ http://www.lazygamer.net/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^lazygamer\.co.za$ [NC]
RewriteRule ^(.*)$ http://www.lazygamer.net/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^lazygamer\.net$ [NC]
RewriteRule ^(.*)$ http://www.lazygamer.net/$1 [R=301,L]


Read up mod_rewrite to understand how to use these for other problems!

RewriteRule ^/([^/]+)/$   /category/$1/ [R]

That should do it.

Beware, this will redirect anything with one directory path in the URL to /category/{original_url_path}

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜