apache - Remove path & extension on URL via htaccess -
i know should easy beating me. after site move want able remove path file along extension (if any) , query string (if any) , index.php (if any) leave file name. eg:
http://www.example.com/folder1/folder2/helloworld.html 301 >> http://www.example.com/helloworld http://example.com/anotherpath/apage.html 301 >> http://www.example.com/apage http://example.com/index.php/blurb/noextension 301 >> http://www.example.com/noextension http://www.example.com/longpath/withsome/morefolders/more.html?dkdhghjghjk 301 >> http://www.example.com/more
there many different paths in original site (with , without www), if file ends in .html (with possibility of query has go well) want redirecting 301 domain/filename
but... make matters more complex, can't redirect
http://www.example.com/category/something
this because category part of new system (it's wordpress).
thanks this!
============
update - having few issues there! adjusted regex suggested , remove .html , query string (if exists) have this.
rewriterule ^.*/([^/]+)(.*)?\.h.*$ /$1? [l,nc,r=301]
however, keeps redirecting home page to
http://www.example.com http://www.example.com/_index
which puzzling me. there in regex?
rewriteengine on
rewriteengine on rewritecond %{request_uri} !^/category/ rewriterule ^.*/([^/]+)\.html$ /$1? [l,nc,r] rewritecond %{request_uri} !^/category/ rewriterule ^.*/([^/]+)$ /$1? [l,nc,r]
there 2 rules because not write in single. first rule files (.html) , second directories (without .html). sign ? after $1 removes query
Comments
Post a Comment