Slim Framework proper htaccess setup with wordpress - php

I want to make an api with slim. it would be on my "tools" subdomain in a directory called api.
http://tools.fifaguide.com/api
What should my .htaccess file look like?
Currently my .htaccess is located in my Wordpress directory (html -> .htaccess), and it looks like this:
<IfModule mod_rewrite.c>
//my part
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/api/index.php
RewriteRule ^api/(.*) http://tools.fifaguide.com/api/index.php [L]
//wordpress part
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The problem with this is that when I try
http://tools.fifaguide.com/api/hello/steve
I imediately get redirected back to api/index.php instead of staying on /api/hello/steve and having the results shown.
Its seems like wordpress is making this happen, but how do I prevent it?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/api/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ api/index.php [QSA,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Related

Htaccess Directive to Show Content of Other Page Pattern URLS

I have the following page patterns:
mydomain.com/?myquery=34
mydomain.com/?myquery=38
mydomain.com/?myquery=42
Which I would like to access the content via:
mydomain.com/myquery/34
mydomain.com/myquery/38
mydomain.com/myquery/42
So when a user gets for example mydomain.com/myquery/34 (this page does not exist), he sees the content of mydomain.com/?myquery=34 (this page exists).
I am using the following htaccess rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteEngine On
RewriteRule ^/myquery/dir1$ /?myquery=dir1 [L]
But the rule does not appear to work. Can you please help?
Can you try this below rules,
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/myquery/(.*)$ index.php?myquery=$1 [L,QSA]

WordPress Htaccess breaking rest of site

To start, I am hosting my website on AWS. I have a normal WordPress site in the root, with a custom application in a sub-folder. The Htaccess in the sub-folder is:
//Htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
And the Htaccess in the root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have a feeling WordPress is screwing up my application in /sub/, cause it was working before I moved Wordpress to the root. If you need additional info, let me know. How do I get Wordpress to ignore that directory?
You need to add default htaccess for root directory of wordpress site.
Read out the documentation here for basic , subdomains , multisite etc.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Place this htaccess in sub folder.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

404 error not work for /%post_id%/%postname%.html

i use /%post_id%/%postname%.html in my wordpress permalink.
404 eror dont work for this permalink if post or page not exist.
but for another link 404 work good.
this is my htaccess file :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
thanks for your help.
Check this might be help you
set apache to "AllowOverride All"
mod_rewrite is present, .htaccess looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wikiarr_prd/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wikiarr_prd/index.php [L]
</IfModule>
# END WordPress
Permalinks structure:
/%postname%_%post_id%.html

Server 500 error - moved app in subfolder

I developed an application in a subfolder of my website and it worked fine.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
RewriteRule ^(.*)$ /app/index.php/$1 [L]
</IfModule>
This file was working fine so and index.php was not required to navigate within the application. Now I moved the application to root of website and changes the last line to
RewriteRule ^(.*)$ index.php/$1 [L]
Now I have start getting Internal Server Error 500. I am not sure that it is something I have done or the .htacces is required to be configured differently. It might be an issue with host too, but I want to exhaust my options first.
Any help will be appreciated. Thanks in advance.
if you in root of hosting you just need
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
if you site in folder /foo you need:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /foo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
RewriteRule ^(.*)$ /foo/index.php/$1 [L]
</IfModule>
if still not working try this, for me it works all over:
RewriteEngine On
RewriteBase /foo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /foo/index.php/$1 [L]

htaccess help in coexisting Codeigniter and Wordpress install

My intention here is to have a codeigniter app with a blog under the same domain. The admin for both should be separate.
The directory structure is this:
httpdocs/.htaccess
httpdocs/application/ <== CI installation
httpdocs/blog/ <== WP installation
httpdocs/blog/.htaccess
URLs would be like this:
mysite.com <== CI
mysite.com/tools <== CI
mysite.com/forum <== CI
mysite.com/blog <== WP
I followed this tutorial to set up and it worked nicely.
Both my codeigniter app and WP blog home page show exactly as they should, with correct URLs, styles etc.
I can also access mysite.com/blog/wp-admin normally for WP back end stuff.
My issue is when I try to access an actual blog post, for example:
mysite.com/blog/fiction/what-is-going-on/
When I do this, I get Codeigniter's 404 error page.
My root .htaccess (httpdocs/.htaccess) is this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt|blog|assets)
RewriteRule ^(.*)$ index.php/$1 [L]
My blog .htaccess (httpdocs/blog/.htaccess) is this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any idea what I'm doing wrong? Will post more info if requested. Thanks in advance.
OK the solution is to use
CI .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
and
WP .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
That did the trick. Now all pages show without a problem.
I generally use 2 sets of conditions on the CI .htaccess (one on the root folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)$ blog/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This will allow the processing of blog URLs first and then deal with the CI URLs. You need to be careful not to have any controllers or routes using the term blog in your application.
I would try three things in your Wordpress .htaccess (don't touch the CI one -- it looks correct):
First, try removing the forward slash from before your index.php:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
If that doesn't work, then instead, try setting the RewriteBase to /blog/:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Finally, if neither of those things work, you can try manually adding "/blog/" to your index.php line at the end:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

Categories