views:

21

answers:

2

Hey Guys,

I am having a hard time getting the rewrite rule setup correctly for my website&blog. Here is the current line in Apache's virtual host:

RewriteRule ^/(?:blog|apc|_em|phpsecinfo|blog/)/ - [L]

I am able to access my URL at www.domainname.com/blog/ But I am unable to access it at www.domainname.com/blog (without the ending /)

How can I edit my Rewrite rule so that I can reach the blog without the ending / ? Thanks

+1  A: 

This should help:

RewriteRule ^/(blog|apc|_em|phpsecinfo)$ /$1/ [R,L]
RewriteRule ^/(?:blog|apc|_em|phpsecinfo)/ - [L]
Ignacio Vazquez-Abrams
I made the change and I could no longer hit the blog with or without the "/". I got this message in the browser, Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
roacha
My bad, I forgot to anchor the end of the first rule.
Ignacio Vazquez-Abrams
Do I need the same "apc,phpsecinfo,etc" on both lines? Or only on the first?
roacha
It depends on whether or not there are any rules after the second. If there are then the second line prevents those paths from being rewritten later.
Ignacio Vazquez-Abrams
A: 

Add the ? modifier to whatever slash you want to make optional:

RewriteRule ^/(?:blog|apc|_em|phpsecinfo)/? - [L]
Álvaro G. Vicario