开发者

mod_rewrite, trailing slashes - one line instead of two?

I have been playing with mod_rewrite using .htaccess to translate some directories - for purposes of both improved SEO and also to produce friendlier/more memorable URLs.

The only problem I can't crack at the moment is with trailing slashes. The behavoir I want is that you should be able to access the link with or without a trailing slash, just to cut down on missed traffic.

My real url is as:

http://www.mydomain.com/shipyard/index.php

I would like people to be able to access it via:

http://www.mydomain.com/shipyard/ 
http://www.mydomain.com/shipyard
http://www.mydomain.com/ships/ 
http://www.mydomain.com/ships 

Of course, the top two are covered because thats actually a real and accessible URL, but I plan to tell Google that the best way to get at the page is using /ships (without having to move directories, break existing links etc).

The best I came up with so far was:

RewriteRule ^ships/$ /shipyard/index.php [L]
RewriteRule ^ships$ /shipyard/index.php [L]

However I just KNOW that i'm using two lines where only one is needed, but whatever I tried, I couldn't get the one! I know i'm missing something incredibly basic 开发者_开发百科and/or obvious, but I need a pointer... Thanks!


RewriteRule ^ships(/)?$ /shipyard/index.php [L]

This means that the slash may or may not be present.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜