apache2 - Apache redirect all sub pages to home page except specific pages -
i have site structure such this:
www.domain.com www.domain.com/subpage-a www.domain.com/subpage-b www.domain.com/terms www.domain.com/request-information
i trying configure apache rewrite rule point all sub pages home page, bar specific pages.
using example above need redirect sub pages of site home page, bar terms
, request-information
pages.
i have been looking on stackoverflow , i've found few questions went unanswered, such this one , this one. second link seems kind of want i'm not sure how override rule specific pages.
my configuration
currently, apache file looks this:
<virtualhost *:80> servername www.domain.co.uk proxypreservehost on rewriteengine on rewriterule ^/(.*)$ http://server:8000/virtualhostbase/http/%{http_host}:80/root/site/virtualhostroot/$1 [l,p] </virtualhost> <virtualhost *:80> servername domain.co.uk redirect permanent / http://www.domain.co.uk/ </virtualhost>
in attempt working appended this, see if sub page redirect:
<virtualhost *:80> servername http://www.domain.co.uk/subpage-a redirect permanent / http://www.domain.co.uk/ </virtualhost>
this didn't work there lot of sub pages site, more of catch-all rule ignored sub pages.
is possible , have ideas?
thanks.
tl;dr
i'm looking 'catch-all' style apache rewrite rule redirect every subpage, bar pages home page of domain.
edit:
with regards answers below have tried following:
answer #1
i modified code following:
<virtualhost *:80> servername sub.domain.co.uk proxypreservehost on rewriteengine on rewritecond %{request_uri} !^/(terms|request-information)(/.*|)$ [nc] rewriterule ^/(.*)$ http://server:8000/virtualhostbase/http/%{http_host}:80/root/site/virtualhostroot/$1 [l,p] </virtualhost> <virtualhost *:80> servername domain.co.uk redirect permanent / http://www.domain.co.uk/ </virtualhost>
however seems 404 pages containing dash, can live unfortunately requires me list of pages redirect in place of terms|request-information
above.
answer #2
i must preserve original re-write rule, multiple re-write rules seem give me "this website not redirecting correctly" message in browser, did copy-and-paste on code amending details necessary resulted witg error.
try in .htaccess
rewriteengine on rewritecond %{http_host} !^(.*)\.your_domain\.com$ [nc] rewriterule ^(.*)$ http://www.your_domain.com/ [r=301,l] rewritecond %{request_uri} !"^/$" rewriterule (.+) http://%{http_host}/ [r=301,l]
this act catch all. make sure redirects set in httpd.conf commented before using this.
let know if helped you. :)
Comments
Post a Comment