.htaccess rewrite parent folder to sub folder - php

how can i redirect from server.ip/~bogo/api/* to server.ip/~bogo/api/public/*?
any help please
Here's htacces in api directory
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
my htacces in public directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
but i got 404 error??

Ok i solved it here's my solution
api directory htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /~bogo/api/
RewriteCond %{REQUEST_URI} !/public/
RewriteRule (.*) public/$1
</IfModule>
public directory htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /~bogo/api/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

Apache will go through .htaccess until no rules match anymore. The problem you are most likely facing, is that the new url is being matched by the regex of the same rule. You have created an infinite loop. You can fix this by making sure the rule doesn't match if the url already has 'public' in it:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/public/
RewriteRule (.*) public/$1 [L]
</IfModule>

Related

Direct all requests to Public directory from .htaccess

I am using this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . public/$1 [L]
</IfModule>
I have tried this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
None of them working properly. Any ideas?
Thank you

im upload me new script to hosting but the website not working main error ERR_too_many_redirects

the .htaccess code is
RewriteEngine off
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule ^(.*) public/$1 [L]
</IfModule>
what is the issue?
I'm not so sure if this is what you want to do, but try with this:
RewriteEngine Off
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ public/$1 [L,QSA]
</IfModule>

Rewrite rule in htaccess - Inner pages of my website not loading however home is loading correctly

askpapa.in/askpapaFinal is opening fine.
See the problem here
root htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /askpapaFinal/
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
App Folder Htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /askpapaFinal/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
webroot htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /askpapaFinal/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Configuring .htaccess files for CakePHP and Wordpress

I have already visited this link:
Configure .htaccess file for multiple environments
But it hasn't resolved my problem.
I am unable to access CakePHP folder from Wordpress directory. This is the .htaccess file of my root:
RedirectMatch 404 /\\.svn(/|$)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myer
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project/trunk/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /project/trunk/index.php [L]
</IfModule>
# END WordPress
This is the .htaccess file of "myer" directory:
RedirectMatch 404 /\\.svn(/|$)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myer
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This is the .htaccess file of "myer/app" directory:
RedirectMatch 404 /\\.svn(/|$)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myer
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
This is the .htaccess file of "myer/app/webroot" directory:
RedirectMatch 404 /\\.svn(/|$)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myer
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
What I am getting out of these .htaccess files is "Object not found! - Error 404". What am I doing wrong?

CakePHP on a Shared Hosting public_html

I have installed my cakephp on a shared host server.
I always get a 404 error
The mod_rewrite looks like this
/home/user/public_html/cms/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
/home/user/public_html/cms/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/home/user/public_html/cms/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
The url is http://server/~user/cms and the server path is /home/user/public_html/cms
you have to add the RewriteBase to remove http://server/~user/ from the url. cake does not work with ~ in the url

Categories