Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: mod_rewrite help |
|
Author |
|
wald-e
Joined: 26 Oct 2020 Posts: 3 Location: Philippines
|
|
Back to top |
|
tangent Moderator
Joined: 16 Aug 2020 Posts: 348 Location: UK
|
Posted: Mon 26 Oct '20 22:17 Post subject: |
|
|
I've tried to work through your example, but it's a bit confusing.
Firstly, you don't say whether oldwiki.samplesite.com and newwiki.samplesite.com are the same host being served through the same Apache. Lets assume they are.
If so, why are you using Alias directives to map to the default htdocs location? They're normally used if you want to reference content from elsewhere on the server filesystem. That said, at some point you were using an alias entry for /Wiki to /mediawiki though it's now commented out, and your mod_rewrite logic doesn't currently redirect to /mediawiki. So either re-enable that alias entry (and maybe consider using AliasMatch instead), or rewrite the URI with mod_rewrite, as well as redirect.
Also, I have encountered problems when using 301 (permanent) redirects rather than 302's (temporary). The problem is browsers (as much as proxies), will cache this result, and not bother contacting the server in the future. This can be a real pain if you make a mistake during testing, or subsequently decide to change the site logic on your server. So I'd recommend using 302 redirects.
I tried the following minor tweaks to your logic on a test instance of Apache, and it seems to work for me:
Code: | Alias /test1 /var/www/html/test1
Alias /test2 /var/www/html/test2
Alias /Wiki /var/www/html/mediawiki
RewriteEngine On
RewriteCond %{HTTP_HOST} !newwiki.samplesite.com$ [NC]
RewriteCond %{REQUEST_URI} ^/Wiki [NC]
RewriteRule ^/(.*)$ http://newwiki.samplesite.com/$1 [R=302,L,NE,QSA] |
Also, before testing, remember to clear your browser cache too. |
|
Back to top |
|
wald-e
Joined: 26 Oct 2020 Posts: 3 Location: Philippines
|
Posted: Tue 27 Oct '20 2:03 Post subject: |
|
|
Hi tangent,
Thanks for the reply. Sorry for not giving enough info - newbie here. They are on a separate server. |
|
Back to top |
|
tangent Moderator
Joined: 16 Aug 2020 Posts: 348 Location: UK
|
Posted: Tue 27 Oct '20 22:09 Post subject: |
|
|
Ok, so if the new wiki site is on a different host, then rather than using mod_rewrite logic, why not just use a Redirect from mod_alias, viz:
Code: | Redirect "/Wiki" "http://newwiki.samplesite.com/mediawiki" |
See http://httpd.apache.org/docs/current/mod/mod_alias.html#redirect for details.
I read through your question again, and at no point does the config you posted reference Main_Page, so that must be either in some other part of your Apache configuration, or your PHP code.
By the way, did you try clearing your browser cache content? |
|
Back to top |
|
wald-e
Joined: 26 Oct 2020 Posts: 3 Location: Philippines
|
Posted: Wed 28 Oct '20 5:48 Post subject: |
|
|
Hi again!
Thanks! the simple Redirect fixed it.
Cheers! |
|
Back to top |
|
|
|
|
|
|