logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

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.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: mod_rewrite help
Author
wald-e



Joined: 26 Oct 2020
Posts: 3
Location: Philippines

PostPosted: Mon 26 Oct '20 9:42    Post subject: mod_rewrite help Reply with quote

Hi,

Can anybody help me with this please?

Here's what I have in conf file of oldwiki site.

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
RewriteRule ^/(.*)$ http://newwiki.samplesite.com/$1 [L,R=301]


----

I am trying to redirect only Alias /Wiki to the newwiki site. But here's the issue now.
http://oldwiki.samplesite.com/Wiki/index.php/Nitro_RC#Setting_up_Nitro_Engine_for_New_Hobbyist
will redirect to -> http://newwiki.samplesite.com/mediawiki/index.php/Main_Page#Setting_up_Nitro_Engine_for_New_Hobbyist

another sample
http://oldwiki.samplesite/Wiki/index.php/How_to_setup_RC_Car
will redirect to ->
http://newwiki.samplesite.com/mediawiki/index.php/Main_Page

It's basically redirecting to Mainpage of the newwiki. Please help
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 348
Location: UK

PostPosted: Mon 26 Oct '20 22:17    Post subject: Reply with quote

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

PostPosted: Tue 27 Oct '20 2:03    Post subject: Reply with quote

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

PostPosted: Tue 27 Oct '20 22:09    Post subject: Reply with quote

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

PostPosted: Wed 28 Oct '20 5:48    Post subject: Reply with quote

Hi again!

Thanks! the simple Redirect fixed it.

Cheers!
Back to top


Reply to topic   Topic: mod_rewrite help View previous topic :: View next topic
Post new topic   Forum Index -> Apache