开发者

RewriteRule - Check if certain Term in URL exists, if not add it

I am currenctly facing some htaccess/rewriterule issues. (And I am new to this area)

Let's assume we have an url like this: http://mypage.at/very/cool

The URL is supposed to look like this (Cause I am using an AJAX-loadedContent which requires this): http://my开发者_如何转开发page.at/#ajx/very/cool

So I would like to add the part '#ajx' to every url which does not already contain it. Which means if an url does already look like: http://mypage.at/#ajx/so/pretty then there is no need for changes.

As I am not sure wheter this creates troubles with the GoogleSearchIndex, I would additionally like to know if there is a way to exclude this rule for searchbots.

Thanks for any help. Ripei


Since you reported that this does not work (which is probably because your version of Apache doesn't support Perl-style RegEx):

RewriteRule ^(?!#ajx)(.*)$ http://mypage.at/#ajx/$1 [L]

I think this should do it:

RewriteCond %{REQUEST_URI} !^/#ajx
RewriteRule ^(.*)$ http://mypage.at/#ajx/$1 [L]

EDIT: After trying this myself and reading around on the Internet, I'm not sure this is actually possible. A pound sign (#) is not a legal part of a URL. This answer comes close, but I'm going to have to leave this to somebody who knows more to say whether this can even be done the way @Ripei asked for.


Something like this might work:

RewriteCond %{REQUEST_URI} !^/#ajx
RewriteRule ^(.*) http://%{SERVER_NAME}/#ajx$1 [R,L]


Hah finally after lot's of reading and testing - I got it.

RewriteCond %{REQUEST_URI} !^#ajx
RewriteRule . /\#ajx%{REQUEST_URI} [L,R,NE]

This Code works for me... don' ask me why this one is working, to be honest I do not have a clue! But well I am fine with the fact, that it IS working :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜