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.
Related
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.
I have content from a different server on a subdomain that I would like to use as a subdirectory. Everything from sub.domain.com should be accessible to domain.com/sub I would like sub folders to work as well ex: sub.domain.com/about should be domain.com/sub/about
Here's my current .htaccess contents
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(sorry).* - [NC,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Any help appreciated. Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^ http://domain.com/sub%{REQUEST_URI} [R=301,L,NE]
I am stuck with .htaccess modification, need a little help.
First off, here is whats inside my htaccess.
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]
For example, I created the file named test.php and uploaded to my server.
I want my server to behave like this.
http://example.com/test/test.html -> http://example.com/test/test.html(as it is)
http://example.com/test/test.php -> http://example.com/test/test.html
but with the .htaccess I have right now,
I still have both .php and .html which may be considered as file duplication by search engine crawler like Google robot (isn't it?).
Any help appreciated.
try this .htaccess code
# Enable Rewrite Engine
RewriteEngine on
#Create friendly URL
RewriteRule ^test/(.*)\.html$ test/$1\.php [L]
OR
RewriteCond %{REQUEST_URI} ^(.*)\.php$
RewriteRule ^(.*) /$1.html [L]
OR
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## .php to .html
# To externally redirect /test/test.php to /test/test.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1.html [R,L,NC]
This is a configuration file of apache '.htaccess' if you still want to configure then change
RewriteEngine on
I hope this work
You may try this in one .htaccess file in root directory:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !\.html [NC]
RewriteRule ^([^/]+)/([^.]+)\.php /$1/$2.html [R=301,NC,L]
For silent mapping, replace [R=301,NC,L] with [NC,L]
I have the following .htaccess file in my root:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
RewriteRule ^([^/]*)$ index.php?page=$1 [NC]
This works as it should for shortening all my URLs to website.com/something
The problem is Google can't find my robots.txt file in my root. The above file isn't letting it through. when It type website.com/robots.txt I get a 404 not found. But if I comment out the above .htaccess code I can get to it just fine.
How can I edit my .htaccess file to let robots.txt through without interfering with my other URLs?
RewriteEngine on
RewriteRule ^robots.txt - [L]
Second line will exclude robots.txt from URL rewritting rules .
Try above code
I tried both suggestions and they both work great. However I went with Kiran's answer simply because it's a shorter syntax. This is what I ended up with.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# remove trailing slash
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
# Allow Robots.txt to pass through
RewriteRule ^robots.txt - [L]
RewriteRule ^([^/]*)$ index.php?page=$1 [NC]
You can use this solution in your .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?page=$1 [L]
This rewrites all your requests to index.php?page=, except the files specified in the RewriteCond list.
Find the line that already exists in your .htaccess that says this:
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
And change it to this:
RewriteRule ^itemap.xml$ index.php?route=feed/google_sitemap [L]
How can I combine the .htaccess rules for CakePHP
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
with the following
RewriteEngine On
RewriteCond %{HTTP_HOST} folder.yoursite.com
RewriteRule ^(.*)$ /folder [L]
in other words redirect anything to app/webroot/ except /blog (which is an existing folder with a WordPress installation) and redirect blog.domain.com to the blog subfolder.
It should work automatically (at least with CakePHP 1.3), it's working for me...
My .htaccess looks like this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
You should also have a proper .htaccess in your wordpress (or any other application) folder that's not a part of the CakePHP application.