Mobile site Rewrite Rules not working correctly for converted version of site if page call is in sub directory

My problem is a little difficult to explain but I think it has to do with the rewrite rules. Basically I have a script that converts a standard site to a mobile site the code is not really supported, by its dev on google code, so I figure I might get some help here I re-coded it a bit so it works with today's phones.

It works fine as long as none of the pages it must access are in a sub so for example the site is www.mysite.com the script is in a sub-domain m.mysite.com the script gets the pages from the main site but appear to be served from the mobile site, a example urls m.mysite.com/mypage.php will work fine and any links on that page do work.

But if the page is in a dir like m.mysite.com/blog/myblog.php it will access that page and you will see /blog in our url but all the links on the page you click will show 404 because they all link as m.mysite.com/myblog.php not m.mysite.com/blog/myblog.php so it does not seem to know that for this page its in /blog even though it is clearly in the url why is it not in the links on the page?

Any ideas what might fix this would this be a rule issue? the htaccess is as follows.

DirectoryIndex phpmobilizer.php

Options +FollowSymlinks
RewriteEngine On

#RewriteCond %{REQUEST_METHOD} =POST
#RewriteRule ^ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ phpmobilizer.php?url=$1 [QSA]

The other issue I have is if it calls a page with a form it will not post I get 404 if I use the rules I have commented out, if I don't add them it will just reload the page no post. Maybe both problems are somehow related, my hope is some expert can help me sort this all out.

Tried to keep this as short as I could but a tad tricky to explain.

How to implement a sub-request in .htaccess?

In Apache I am trying to emulate the RewriteLog behaviour with a sub-request pointing to a simple cgi script

According to Apache 2.2 documentation:

%{LA-U:variable} can be used for look-aheads which perform an internal (URL-based) sub-request to determine the final value of variable. This can be used to access variable for rewriting which is not available at the current stage, but will be set in a later phase.

%{LA-F:variable} can be used to perform an internal (filename-based) sub-request, to determine the final value of variable. Most of the time, this is the same as LA-U above.

According to a mail archive conversation in the case of using %{LA-F:variable} the request is passed directly to the next processing stage:

usr/local/webserver/doc_root/some/dir/som_file

cat /dev/world | perl -e "while (<>) {(/(^.*? \?) 42 \!/) && (print $1)}"
errors->(c)

but how to implement %{LA-U:variable} or %{LA-F:variable} in .htaccess?

CodeIgniter always shows 404 error

I am using and I have set its default controller in routes.php as

$route['default_controller'] = 'home';

I have set the Virtual Host for this project and my .htaccess looks like this

<IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
 </IfModule>
<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule !^[A-Za-z0-9_/\-\.]*$ - [L,R=404]
</IfModule>

<IfModule !mod_rewrite.c>

  ErrorDocument 404 /index.php
</IfModule>

My config.php is like

$config['index_page'] = '';

It is working fine if the default controller is set to welcome

apache poi get default column type

I'm using POI to create a new row of cells in an existing spreadsheet. POI allows you to get the column default style, but there's no equivalent (as near as I can tell) to getting a default type. I'm getting a String from my user interface and I don't know how to set the cell type. If the string is a double, then fine, it's NUMERIC. But if the String specifies a date, how would I best detect it so that it is also set to NUMERIC? There are some many formatting types for a date that it is impractical to detect the type from the cell style format. Does POI support a way to parse based on a format?

Unable to initialize JCR_MOCK resource resolver factory – sling mocks

I have a simple sling mock test that is loading json data

public class Test {

    @Rule
    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_MOCK);

    @Before
    public void setUp() {
        context.load().json("/test-1.json", "/content/test");
    }

    @Test
    public void testLoad() {
        Resource resource = context.resourceResolver().getResource("/content/test");
    }
}

I have the following dependencies added to my pom.xml

    <dependency>
        <groupId>org.apache.sling</groupId>
        <artifactId>org.apache.sling.testing.sling-mock</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.sling</groupId>
        <artifactId>org.apache.sling.commons.testing</artifactId>
        <version>2.0.16</version>
        <scope>test</scope>
    </dependency>

When i execute this, I get the following exception, even though sling.api (v2.2) is an existing dependency in the pom

java.lang.RuntimeException: Unable to initialize JCR_MOCK resource resolver factory.
    at org.apache.sling.testing.mock.sling.context.ContextResourceResolverFactory.get(ContextResourceResolverFactory.java:66)
    at org.apache.sling.testing.mock.sling.context.SlingContextImpl.newResourceResolverFactory(SlingContextImpl.java:103)
    at org.apache.sling.testing.mock.sling.context.SlingContextImpl.setUp(SlingContextImpl.java:94)
    at org.apache.sling.testing.mock.sling.junit.SlingContext.access$000(SlingContext.java:32)
    at org.apache.sling.testing.mock.sling.junit.SlingContext$1.before(SlingContext.java:113)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.NoClassDefFoundError: org/apache/sling/api/resource/ResourceProviderFactory
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.apache.sling.testing.mock.sling.MockJcrResourceResolverFactory.getResourceResolverInternal(MockJcrResourceResolverFactory.java:74)
    at org.apache.sling.testing.mock.sling.MockJcrResourceResolverFactory.getResourceResolver(MockJcrResourceResolverFactory.java:111)
    at org.apache.sling.testing.mock.sling.context.ContextResourceResolverFactory.initializeJcrMock(ContextResourceResolverFactory.java:72)
    at org.apache.sling.testing.mock.sling.context.ContextResourceResolverFactory.get(ContextResourceResolverFactory.java:52)
    ... 21 more
Caused by: java.lang.ClassNotFoundException: org.apache.sling.api.resource.ResourceProviderFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 37 more

Can someone please help?

How to make apache choose a particular python executable in a virtualenv for django

I am trying to make apache deliver a django test site that resides in a particular virtualenv using the python executable of that virtualenv, but it refuses to use anything except the default system python.

I'm working on a server running RedHat. Apache2 and mod_wsgi are installed along with python 2.6.6. I have an old site that runs on python 2.4 and django 1.2 that I want to upgrade, but first I need to get it running in those versions in a virtualenv setup with python 2.4. I have every step working EXCEPT I cannot seem to get apache to change the python executable it uses to deliver the django site. For testing purposes, I'm just using the django default "It Work!" initial page, then intentionally forcing a programming error to have the django error page tell me which python executable is being used to deliver it.

The VirtualHost section of my httpd.conf file is:

<VirtualHost *:443>
    #WSGIScriptAlias / var/www/mysite/index.wsgi
    #WSGIDaemonProcess python-path=/home/jnett/python24sites/lib/python2.4/site-packages
    <Location "/python24sitetest">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        PythonOption django.root /python24sitetest
        SetEnv DJANGO_SETTINGS_MODULE python24sitetest.settings
        SetEnv PYTHON_EGG_CACHE "/tmp"
        PythonPath "['/var/www/python24sitetest', '/var/www'] + sys.path"
        PythonDebug On
        PythonInterpreter python24sitetest
    </Location>
</VirtualHost>

I have tried every possible combination/permutation of WSGIDaemonProcess, WSGIPythonPath, and WSGIPythonHome that I can think of, but apache ALWAYS only uses the system default python 2.6 no matter what I try.

How do I force apache to deliver just this particular django site using the particular python executable of the virtualenv in which it resides?

[EDIT] I have also tried adding a WSGIScriptAlias to httpd.conf (commented above), where the file index.wsgi is located in the home directory of the django project and contains

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/jnett/python24sites/lib/python2.4/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('//home/jnett/python24sites/projects/mysite')

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

# Activate your virtual env
activate_env=os.path.expanduser("/home/jnett/python24sites/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

I still get no effect at all.

Dynamic DirectoryIndex (Regex DirectoryIndex?)

In Apache, is it possible to have a dynamic/regex DirectoryIndex Directive?

Normal DirectoryIndex would do:

server/DIRECTORY1 --> server/DIRECTORY1/index.html
server/DIR1/DIR2  --> server/DIR1/DIR2/index.html
...
etc

But how would I accomplish:

server/DIRECTORY1 --> server/DIRECTORY1/DIRECTORY1.html
server/DIR1/DIR2  --> server/DIR1/DIR2/DIR2.html
...
etc

I want this because I have many index files open in my editor, and it's hard to tell the tabs apart because they're all named index.

  • I'd prefer something that'll work site-wide in httpd.conf
  • I want to keep the with/without trailing-slash detection that mod_dir has.
  • My attempts using mod_rewrite tend to mess up the URI variables at the end :(

Apache Components and Spring Boot

I am trying to include the latest version of the apache httpclient libraries in my spring boot application. When I try to compile the app I get a bunch of package does not exist / cannot find symbol.

ex.  error: package org.apache.http does not exist
ex.  error: package org.apache.http.client.config does not exist
ex.  error: package org.apache.http.conn.socket does not exist
ex.  class HttpContext cannot find symbol

Below are the relevant parts of my build.gradle

buildscript {
repositories {
maven { url "https://repo.spring.io/libs-release" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.spring.io/libs-release" }
}

dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
//excluding a particular transitive dependency:
exclude group: 'commons-logging' //by group
exclude group: 'ch.qos.logback' //by group
}

compile 'org.apache.httpcomponents:httpclient:4.4'
compile 'org.apache.httpcomponents:httpcore:4.4'
compile 'org.apache.httpcomponents:httpmime:4.4.1'
}

task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}

Any idea why id doesn't seem to be able to find the classes?

Thanks, Nathan

Php website is running on local server, not on web server [on hold]

Ok I have a website that uses Php, javascript, html, css and sql. (just clarifying for detail).

I've been coding it for a whole month, and it's finally ready to upload. So I put all the files on my web server, and every page is blank when you view the page in the browser, but all the code is still there on the server.

I check the page source, and all that's there is the html comment at the top of my included header.php file. (<-- some comment -->) I am pretty advanced at this stuff, but I can't figure out what's wrong. Things that are not wrong (I triple checked):

  1. Wrong file paths (also url address)
  2. Wrong database connection information
  3. file permissions
  4. php server configuration (I have other similar sites on the same server)
  5. The .htaccess file. If there is anything else you can think of that may be wrong please help me!

SlimPHP and Routing – am I doing it wrong?

So I recently, as in a day or so ago, asked about why my routes were not working for slim and according to the answer, I made the appropriate changes, but unless I am doing routing wrong, they are not working.

If we look at the routing file I have set up, which is required in the index.php file, we can see:

<?php
use \ImageUploader\Controllers as Controller;
/** ---------------------------------------------------------------- **/
// Routes.
//
// Routes are defined here. Nothing should happen in a route other then
// Calling  acontroller based action, such as: indexAction.
/** ---------------------------------------------------------------- **/
$app = new \Slim\Slim();

$app->get('/', function(){
    Controller\HomeController::showHome();
});

$app->get('/signup', function(){
    Controller\SignupController::showSignupForm();
});

$app->post('/signup/new', function() use ($app){
   var_dump($app->request()->post('username'));
   var_dump($app->request()->post('password'));
});

// Don't touch.
$app->run();

That I have a few routes listed. Now I can go to the first one, it displays the contents of the HomeController::showHome, but if I try and navigate to http://localhost/image-upload/signup I get:

Not Found

The requested URL /image-upload/signup was not found on this server.

Now my project doesn't sit in the root directory, it sits in image-upload, so when I just go localhost/image-upload I see the / route execution results.

My htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /image-upload/

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>

Also my index.php file looks like:

<?php
/** ---------------------------------------------------------------- **/
// This is the core app.
/** ---------------------------------------------------------------- **/
if (!file_exists('bootstrap.php')) {
    throw new \Exception('Where is the bootstrap.php?');
}

require_once 'bootstrap.php';

/** ---------------------------------------------------------------- **/
// Routing.
/** ---------------------------------------------------------------- **/
require_once 'app/routes.php';

Am I doing slim routing wrong or ...

Changes Made

Fixed the rewrite base, it was suppose to be /image-upload/. This how ever did not fix any issues. Mod Rewrite is enabled and on.

Some one suggested pre-pending image-upload/ (or similar) to the core routes of slim. This does not help. in fact it breaks routing.