facebook

setting up .htaccess

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #315470 Reply

    Greg Soulsby
    Member

    This may not be a Spring specific issue, applogies if not.

    Firstly, where do I put my .htaccess file within the directory structure so it is picked up by apache? Say I create a web project XXX and scafold. If I put the .htaccess file in XXX or in xxx/Webroot, then I re-boot and execute the ->Run As -> My Eclipse Server.

    Either way, it doesnt seem to be bing picked up the re-directs.

    And when I solve that problem, can you give an example of how the RewriteRule rule should look? Where will the roots of the from and to be? I want to re-direct http://www.mysite.com/from to /xxx?p=nnn

    Thanks

    #315503 Reply

    Glen Ihrig
    Member

    Hi P0rridge,

    First, .htaccess does not belong in the java application as tomcat does not support it. .htaccess is an apache httpd configuration file.

    Here are a couple of discussions elsewhere on the web that may be of help:

    Setting up .htaccess in the apache httpd web server, has an example of configuring .htaccess to pass some urls to tomcat.
    http://stackoverflow.com/questions/4439732/creating-htaccess

    More info on connecting apache httpd to tomcat, a bit “rambling” but may be of help:
    http://old.nabble.com/Urgent%3A-how-to-run-htaccess-on-tomcat-td30027054.html

    And, there’s always the official docs:
    http://tomcat.apache.org/connectors-doc/

    But if all you are looking to do is map the “/from” url path to a service you have created with ME4S, have a look in your existing web app for examples:

    1. See servlet-mapping in web.xml
    2. Examine the java for an existing controller.
    – Look in generated/xxx/web/XxxController.java.
    – Search for code where @RequestMapping is used.

    Regards,

    -Glen

    #315610 Reply

    jkennedy
    Member

    Thanks for the information Glen, we appreciate it.

    #315638 Reply

    Greg Soulsby
    Member

    Thanks Glen. This is where I have got to

    For managing re-directs within your app, this is incredibly good: http://www.tuckey.org/urlrewrite/ Simple to set up and works great on both inbound re-directs and changing your URLs in your outbound pages to the right value.

    But you still have to get a web request to the root of the site to be answered by the /xxx/ server.

    For that I can only see you cant do that from within xxx. You need an Apache re-direct. For that, in Ubuntu, you have to
    a) allow .htaccess processing within your Apache setup, which means edit /etc/apache2/sites-available/default and set AllowOverride None to AllowOverride All
    b) creating a .htaccess file with the following:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example\.com$
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    RewriteRule ^$ xxx [L]

    Please let me know how wrong I am – am going to come back to this and try it in a few days.

    #315645 Reply

    Glen Ihrig
    Member

    Hi P0rridge,

    I guess I’m not quite sure exactly what you are tying to accomplish.

    I’m not a big fan of complex .htaccess rules, so I’m not going to be much help there. If you already have Apache httpd installed to serve static content then you may not be too far off base, assuming that you have a connector such as mod_jk in place, but again, I don’t have experience in that area.

    From your original post:

    >I want to re-direct http://www.mysite.com/from to /xxx?p=nnn

    Which I interpret to mean you want to redirect

    http://www.mysite.com/from

    to

    http://www.mysite.com/xxx?p=from

    Looks like you should be able to do that with URLRewrite (excellent find on that, by the way, thanks for sharing!)

    From your previous post

    >But you still have to get a web request to the root of the site to be answered by the /xxx/ server.

    If you are trying to work out how to get http://www.mysite.com to be served by /xxx on tomcat…
    As you may know, Tomcat has a default app that will be resolved at “/”. If you have only one app on your tomcat install, placing it in webapps/ROOT makes that happen. you don’t even need to rename your context and all that spring config stuff. Just export your project to xxx.war and rename that to ROOT.war and deploy. I don’t think this applies to the MyEclipse sand box tomcat, but I have never tried that.

    If you are still trying to get web traffic to tomcat, I have done this on Ubuntu using the ShoreWall fire wall as configured through Webmin. It’s even possible to set up port specific redirects for SSL and such. e.g 80 -> 8080 and 443 -> 8443, etc.

    If you need to host multiple sites under one tomcat installation, have a look at the tomcat docs for virtual hosting at http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html In production, I prefer to set up virtual copies of Ubuntu one per domain. I have had good luck using VMWare Server which is free after registration.

    Regards,

    -Glen

    #315647 Reply

    Glen Ihrig
    Member

    One last note on webapps/ROOT. In the default Tomcat install, the tomcat manager is installed in ROOT. I delete manager for production use, but you may want to move it before deploying your own ROOT.war.

    -Glen

    #315679 Reply

    Greg Soulsby
    Member

    Glen, this is why I think computers wont catch on – its all too hard.

    My situation is this: have a number of web apps generated in MyEclipse, broken down by nice tight functions – user management, content management, business records etc. Love this, much better design than the old monolithic thing.

    These we want to collaborate via Restful web services. Love this too – keeps interfaces clean and elegant.

    One of the web apps is the content manager, which servers the web pages. This is app xxx

    So I want a user who requests http://www.brandA.com/YYY to be redirected to http://www.brandA.com:8080/xxx/YYY, where YYY could be anything

    .htaccess is only re-directing port 80, ignoring 8080. So I now hope that all requests to port 80, like http://www.brandA.com, will go to :8080/xxx and all the back end web service requests on 8080 will be untouched. So far so good.

    The issue now is that the user typing http://www.brandA.com is seeing http://www.brandA.com:8080/xxx in their browser.

    I am hoping I can use the fantastic URLRewrite re-write rule to fix that.

    Unless you have a better approach, which I am sure you do!

    #315712 Reply

    Glen Ihrig
    Member

    Hi P0rridge,

    this is why I think computers wont catch on – its all too hard.

    I feel your pain man. I live there way too often!

    > So I want a user who requests http://www.brandA.com/YYY to be redirected to http://www.brandA.com:8080/xxx/YYY, where YYY could be anything

    > The issue now is that the user typing http://www.brandA.com is seeing http://www.brandA.com:8080/xxx in their browser.

    It looks to me like you need two different redirects:

    1. brandA.com:80 > brandA.com:8080
    2. brandA.com/ > brandA.com/xxx – but you want the user to still see brandA.com/ in their browser?

    In case 1. there are several ways to do this (Apache+mod_jk, apache+mod_proxy, JSVC, firewall). The only method I have had success with is using a firewall to redirect site.com:80 > site.com:8080 and site.com:443 > site.com:8443. I have not tried Apache+mod_* and I have tried and failed with JSVC.

    I would handle 2. by installing app xxx as ROOT as described above.

    >But you still have to get a web request to the root of the site to be answered by the /xxx/ server.

    If you are trying to work out how to get http://www.mysite.com to be served by /xxx on tomcat…
    As you may know, Tomcat has a default app that will be resolved at “/”. If you have only one app on your tomcat install, placing it in webapps/ROOT makes that happen. you don’t even need to rename your context and all that spring config stuff. Just export your project to xxx.war and rename that to ROOT.war and deploy.

    There’s also virtual hosting under tomcat http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html

    But you may be able to do this using URL Rewrite Filter.

    I think if you tackle these two separate redirect problems individually it will go a lot easier.

    Regards,

    -Glen

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: setting up .htaccess

You must be logged in to post in the forum log in