action-based mod_rewrite

New to mod_rewrite? This is a good place to start.

action-based mod_rewrite

Postby roskha » Sat Jun 13, 2009 12:21 pm

I apologies for re-using the topic: do not have permission to create a separate one.

Here is my question:

I have 2 URLs:
incoming - http://url1.no.ip.info
conditional redirect - http://url2.no-ip.info

I want to redirect to url2 only if the incoming url is built like this:
http://url1.no.ip.info/public/searchbuild.do

If "public/searchbuild.do" is present, I want to redirect to url2, otherwise use url1.

Please, help.

Thank you.
roskha
 
Posts: 4
Joined: Sat Jun 13, 2009 12:03 pm

Postby richardk » Sat Jun 13, 2009 3:29 pm

I apologies for re-using the topic: do not have permission to create a separate one.

New Threads/Problems

All registered users can post in this forum. To start new threads in the other forums, you must add yourself to the Humans usergroup (and be approved). Any new threads in this forum will be moved to the appropriate forum.

You can create a threads in the New Threads/Problems Forum.

If "public/searchbuild.do" is present, I want to redirect to url2, otherwise use url1.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^url1\.example\.com$ [NC]
RewriteRule ^public/searchbuild\.do$ http://url2.example.com%{REQUEST_URI} [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby roskha » Sat Jun 13, 2009 5:33 pm

Thank you for the prompt reply. Does not work yet. The problem is, it works if I enter http://url1.no-ip.info/public/searchbuild.do, but if I just enter
http://url1.no-ip.info, I get error 500. Here is the code:

<VirtualHost *:80>
<Directory />
Options +FollowSymLinks
</Directory>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^url1\.no-ip\.info$ [NC]
RewriteRule ^/public/searchbuild\.do$ http://url2.no-ip.info [R=301,L]
ServerName url1.no-ip.info
JkMount /* cityside
</VirtualHost>

Thank you.
roskha
 
Posts: 4
Joined: Sat Jun 13, 2009 12:03 pm

Postby richardk » Sun Jun 14, 2009 10:26 am

Does it happen without the mod_rewrite?

Code: Select all
<VirtualHost *:80>
  ServerName url1.no-ip.info
  JkMount /* cityside

  Options +FollowSymLinks

  RewriteEngine On

  RewriteCond %{HTTP_HOST} ^url1\.no-ip\.info$ [NC]
  RewriteRule ^/public/searchbuild\.do$ http://url2.no-ip.info/ [R=301,L]
</VirtualHost>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby roskha » Sun Jun 14, 2009 11:23 am

Richard, if I understood your question correctly, I tried exactly the way you have in the Code block, and it is the same problem. I also tried this with the same result: when url is http://url1.no-ip.info, I get 500. Also tried without RewriteCond ang got the same error.

<VirtualHost *:80>
ServerName url1.no-ip.info
JkMount /* cityside
<Directory />
Options +FollowSymLinks
</Directory>
RewriteEngine On
RewriteCond %{request_uri} ^/public/searchbuild(.*)$ [NC]
RewriteRule ^/public/searchbuild(.*)$ http:/url2.no-ip.info [R=301,L]
</VirtualHost>
roskha
 
Posts: 4
Joined: Sat Jun 13, 2009 12:03 pm

Postby richardk » Sun Jun 14, 2009 11:30 am

What about with no mod_rewrite
Code: Select all
<VirtualHost *:80>
  ServerName url1.no-ip.info
  JkMount /* cityside

  Options +FollowSymLinks
</VirtualHost>


Edit: What does your error log say is causing the error?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby roskha » Sun Jun 14, 2009 4:26 pm

Richard, thank you. On your instructions I looked in the log and saw that the JkMount was incorrect. Now everything works. Thank you for your time.
roskha
 
Posts: 4
Joined: Sat Jun 13, 2009 12:03 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 104 guests

cron