WordPress .htaccess – route other URLs to another app

I need help in WordPress .htaccess. My projects name is Project this is WordPress and onepage website, inside this I have one more project that is built in CI named app. What I want is, if someone enters anything after /, then get content from CI App project. I do not want to redirect user to http://example.com/app/<anything>. As i said wordpress project is one page, so when i click on navigations i got !# like characters in url.

http://example.com/<anything>

My current .htaccess is

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /project/index.php [L]
</IfModule>
# END WordPress

Is it possible?

1 Answer
1

Since your WordPress site is just a one-page site, this is served from the single URL http://example.com/. You then want http://example.com/<something> to be internally rewritten to http://example.com/app/<something>.

You can add the following mod_rewrite directives before your existing WordPress directives (ie. WordPress front-controller) in your root .htaccess file:

# Route all URL-paths (of 1 or more characters) to CI app
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule (.+) /app/$1 [L]

# WordPress directives start here...
:

The RewriteCond directive that checks against the REDIRECT_STATUS environment variable ensures that only initial requests are rewritten, as opposed to internal rewrites to index.php by WordPress.

The RewriteRule pattern (.+) ensures we only match URL-paths longer than one character, missing the document root – which is passed through to WordPress.

Leave a Comment