I'm having a problem with rewrite rules in my cake 2.2.0 app.
Mod_rewrite seems to be working as going here:
myapp.com/listings works
But links generated by cake construct this type of URL, which also work but are not being rewritten:
myapp.com/app/webroot/index.php/listings
I've tried a lot of posted options but nothing seems to work?
My apache config is set up as follows:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
All .htaccess files are standard from the cake install?
Webroot .htacess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
App .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Should I be looking at anything else?
This is something you should be able to fix in cakephp when you generate your links. The htaccess files that you have won't change the links in your page content.
If for whatever reason, you can't do this in cakephp, then you can add this to your Webroot htaccess, right below the RewriteEngine On line:
RewriteCond %{THE_REQUEST} \ /app/webroot/index.php/([^\ ]+)
RewriteRule ^ /%1 [L,R=301]
and that will redirect the browser to the shorter URL.
In case any one else looks at this, my problem was that this line in /app/Config/core.php was uncommented:
Configure::write('App.baseUrl', env('SCRIPT_NAME'));
Commenting it out removed the abs URL /app/webroot/index.php/ from my URLs.
Happy coding.
Related
I'm struggling with the .htaccess file. I've wordpress installed in a subdirectory 'wordpress'. In the root folder if have the htaccess with the following content:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule !^wordpress/ /wordpress%{REQUEST_URI} [L,R=301]
</IfModule>
Redirection is working, but how can I hide the subfolder 'wordpress'?
THX in advance
EDIT: Tried following content now but still not working:
root htaccess:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
</IfModule>
wordpress htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
EDIT2: my whole root htaccess looks like this now:
Allow from all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
If i type in www.example.com I am redirected to example/wordpress/home, example/wordpress/contact and so on...
I would like to hide the wordpress directory like example/home, example/contact and so on
Redirection is working, but how can I hide the subfolder 'wordpress'?
You shouldn't be "redirecting". You should be internally rewriting the request instead. Remove the R flag.
For example:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
The slash prefix on the susbtitution string is also not required.
This assumes you have the standard WP .htaccess file in the /wordpress subdirectory.
UPDATE: Also confirm you have removed the /wordpress subdirectory from the "Website Address" and "Site Address" in WordPress General settings.
I've created a Syfmony 5.2 project and on my local I've used symfony serve -d. So, when I've put the project live, I need an .htaccess file. Well, it looks like below:
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
The result?
The page isn’t redirecting properly
Please, can someone tell me what I've missed?
please have a look here:
https://symfony.com/doc/current/setup/web_server_configuration.html
I am not very familiar with Apache, I usually use NGINX but on first look, it looks like you need to define a document root to /var/www/project/public.
I hope you can move forward with this information.
Please can somebody take a look at my .htaccess code to help identify what's wrong.
I am trying to amend all example.php, example.html and example.htm URL's to index.php?filename=example.html
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(index\.php) - [L]
RewriteRule ^([^/\.]+).(php|html|htm)$ index.php?filename=$1.html&%{QUERY_STRING} [L]
</IfModule>
When I enter a URL like example.html I'm taken to the default 404 and not index.php
Try:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?filename=$1 [L,QSA]
</IfModule>
I'm not using the apache .hatacces for a while,
But try this one:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} !^.*/(css|img|js)($|/.*$) [NC]
RewriteRule ^(.*)$ /index.php?filename=$1&%{QUERY_STRING} [L]
Basically what you need is to be sure that the URL didn't have already index.php. You accomplish it with RewriteCond.
After you redirect all to index.php passing the filename as a parameter.
You can add more exception to the RewriteCond like on this example, all content with /css, /js, /img will not pass to this rule.
You can check this thread: Using .htaccess to reroute all requests through index.php EXCEPT a certain set of requests also
Im using an MVC framework for my PHP application which works great. I have the below code in a .htaccess file in the root folder of my application. This redirects everything to the public folder which is causing issues for me. I want to apply the below to everyfolder apart from one. How would I go about doing this? ie. need to access the /dompdf/ directory and all subdirectories normally wihtout the below rule which redirects.
#<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
# </IfModule>
I think if I understand what you want, this should help -
#<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^dompdf [L,NC]
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
# </IfModule>
Replace your existing code with this one:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule (?!^(dompdf|public)/)^.*$ public%{REQUEST_URI} [L,NC]
Negative lookahead will prevent application of these rules for paths dompdf and public.
I have my site www.mysite.com in /var/www/
and I added my cakephp app in /var/www/developer
when I go to www.mysite.com/developer I get the login page fine and after I login the app takes me to the home page OK. But whenever I click on other link I get
"Page not found"
I have 3 htaccess
/var/www/developer
/var/www/developer/app
/var/www/developer/app/webroot
What should I put on those to make my urls work?
Thanks
Your .htaccess files should probably look like this:
/var/www/developer
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
/var/www/developer/app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/var/www/developer/app/webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
You also should have right paths defined in /var/www/developer/app/webroot/index.php
instead of
if (!defined('ROOT')) {
define('ROOT', dirname(dirname(dirname(__FILE__))));
}
try something specify the right way (eq. DS . 'www' . 'develop')
usually it is enough to redefine just CAKE_CORE_INCLUDE_PATH but sometimes youe needed define all three ROOT WEBROOT_DIR nad CAKE_CORE_INCLUDE_PATH