.htaccess - RegEx to find whole word, but not abbreviation -


i using regex in .htaccess file determine uris sent router file. have problem though because 1 page need route contains string i'm filtering out, causing uri not sent router. don't want uris "adm" in them sent router, means filters out uris strings "admonish" or "administrate".

.htaccess:

<ifmodule mod_rewrite.c>     options +followsymlinks     # options +symlinksifownermatch     rewriteengine on     rewritebase /     rewritecond %{https} off     #rewriterule (.*) https://%{http_host}%{request_uri} </ifmodule>  <ifmodule mod_rewrite.c>   rewritecond %{https} !=on   rewritecond %{http_host} ^www\.(.+)$ [nc]   rewriterule ^http://%1%{request_uri} [r=301,l] </ifmodule>  rewritecond %{request_filename} !-f rewriterule !(^adm|^ajax|^google([a-z0-9])|^tools|^swf|^confirm|^style) index.php [nc] 

i've tried things rewriterule !(^adm(![in])|^ajax|^google([a-z0-9])|^tools|^swf|^confirm|^style) index.php [nc] , rewriterule !(^adm(!in)|^ajax|^google([a-z0-9])|^tools|^swf|^confirm|^style) index.php [nc], no success.

what correct way match portion of word if not followed characters other "/"?

edit - current rewrite suggested:

rewritecond %{request_filename} !-f rewriterule !(^(?i)\badm(?=[a-z])|^ajax|^google([a-z0-9])|^tools|^swf|^confirm|^style) index.php [nc] 

still no luck this, though.

update - full .htaccess file:

   directoryindex index.php  <ifmodule mod_rewrite.c>     options +followsymlinks     # options +symlinksifownermatch     rewriteengine on     rewritebase /     rewritecond %{https} off     #rewriterule (.*) https://%{http_host}%{request_uri} </ifmodule>  <ifmodule mod_rewrite.c>   rewritecond %{https} !=on   rewritecond %{http_host} ^www\.(.+)$ [nc]   rewriterule ^http://%1%{request_uri} [r=301,l] </ifmodule>  rewritecond %{request_uri} !/(adm|ajax|google([a-z0-9])|tools|swf|confirm|style) [nc] rewritecond %{request_filename} !-f rewriterule . index.php [l]  # rewrite requests sitemap.xml rewriterule sitemap.xml$ sitemap.php?target=google [l] # rewrite requests urllist.txt rewriterule urllist.txt$ sitemap.php?target=yahoo [l]  options -multiviews   # ---------------------------------------------------------------------- # custom 404 page # ----------------------------------------------------------------------  # can add custom pages handle 500 or 403 pretty easily, if like. # if hosting site in subdirectory, adjust accordingly #    e.g. errordocument 404 /subdir/404.html errordocument 400 /error.php?e=400 errordocument 401 /error.php?e=401 errordocument 403 /error.php?e=403 errordocument 404 /error.php?e=404 errordocument 500 /error.php?e=500   # ---------------------------------------------------------------------- # utf-8 encoding # ----------------------------------------------------------------------  # use utf-8 encoding served text/plain or text/html adddefaultcharset utf-8  # force utf-8 number of file formats addcharset utf-8 .atom .css .js .json .rss .vtt .xml  # ---------------------------------------------------------------------- # little more security # ----------------------------------------------------------------------  # avoid displaying exact version number of apache being used, add # following httpd.conf (it not work in .htaccess): # servertokens prod  # "-indexes" have apache block users browsing folders without # default document should leave activated, because # shouldn't allow surf through every folder on server (which # includes rather private places cms system folders). <ifmodule mod_autoindex.c>   options -indexes </ifmodule>  # block access "hidden" directories or files names begin # period. includes directories used version control systems such # subversion or git. <ifmodule mod_rewrite.c>   rewritecond %{script_filename} -d [or]   rewritecond %{script_filename} -f   rewriterule "(^|/)\." - [f] </ifmodule>  # block access backup , source files. these files may left # text/html editors , pose great security danger, when can access # them. <filesmatch "(\.(bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$">   order allow,deny   deny   satisfy </filesmatch>  # increase cookie security <ifmodule php5_module>   php_value session.cookie_httponly true   php_value error_log /logs/php_errors.log </ifmodule>   # prevent access php error log <files php_errors.log>  order allow,deny  deny  satisfy </files> 

edit again: have tried:

rewritecond %{request_uri} !((adm[^/]+)/|ajax|google([a-z0-9])|tools|swf|confirm|style) [nc] rewritecond %{request_filename} !-f rewriterule . index.php [l,nc]  rewritecond %{request_uri} !/((.*)/adm/(.*)|ajax|google([a-z0-9])|tools|swf|confirm|style) [nc] rewritecond %{request_filename} !-f rewriterule . index.php [l,nc] 

negative lookahead

if i'm understanding correctly, basic pattern you're looking (with possible refinements) is:

adm(?![a-z]) 
  • (?![a-z]) lookahead ensures following character not letter.

  • in mod-rewrite, can make case-insensitive (?i)adm(?![a-z])


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -