开发者

HTAccess Rewrite Needed

I need to rewrite any url on my domain that starts with **/club/***anyPage* to /pa开发者_运维技巧ge/club/anyPage.

For this, I believe I can use the following command:

RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]

Also, if the physical page does not exist I want it conditionally rewritten like so:

/club/$1 to /page/club/club.php?title=$1

So in this case if the user enters in mysite.com/club/New_Club they should actually be viewing /page/club/club.php?title=New_Club


Your original rules seems to work OK for it's job, but to encorporate the second requirement, something like this should do the job...

# do first rule if not file/directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^club/([^/]*)$ /page/club/club.php?title=$1 [NC]
# do second rule if not file/directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]

or depending on other rules...

# prevent requests for real files / directories from rewritting at all
RewriteCond %{REQUEST_URI} -f
RewriteCond %{REQUEST_URI} -d
RewriteRule .* - [L]

RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]
RewriteRule ^club/([^/]*)$ /page/club/club.php?title=$1 [NC]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜