.htaccess: Removing /index.php/foo - .htaccess

I have a site built with Contao. I just turned on URL rewriting and now index.php/foo returns a 404 error. I tried to rewrite /index.php/foo to /foo with
RewriteCond %{REQUEST_URI} ^/index\.php/
RewriteRule ^index.php/(.*) /$1 [R,L]
but it does not help.
Here's the rewrite part of the contao factory .htaccess with my additions in it's entirety (I edited out all the commented stuff to make it shorter):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/index\.php/ # My rule here
RewriteRule ^index.php/(.*) /$1 [R,L] # My rule here
<FilesMatch "\.(png|gif|jpe?g|js|css|ico|php|xml|csv|txt|gz|swf|flv|eot|woff|svg|ttf|htm)$">
RewriteEngine Off
</FilesMatch>
RewriteRule .*\.html$ index.php [L]
RewriteRule ^[a-z]{2}/$ index.php [L]
RewriteRule ^([a-z]{2})$ $1/ [R=301,L]
</IfModule>
What am I not getting here?

Never mind. I found the answer.
<FilesMatch "\.(png|gif|jpe?g|js|css|ico|THIS HERE CAUSED IT: --> ***php***|xml|csv|txt|gz|swf|flv|eot|woff|svg|ttf|htm)$">
RewriteEngine Off
</FilesMatch>

Related

Safely move my blog?

My blog is currently located at:
example.com/blog
with posts being something like:
example.com/blog/my-post
I want to edit my htaccess file so anyone that accesses
example.com/blog/my-post
would end up at:
example.com/my-post
How can I do this with an htaccess file?
UPDATE
Right now I have:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# www.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
</IfModule>
That will forward any non-www traffic to www. However, I need to modify this to support /blog as well. I don't think my syntax is right:
RewriteCond %{HTTP_HOST} ^example\.com/blog$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
?
You cannot match /blog using HOST_NAME variable.
Have your htaccess like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# www.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301,NE]
RewriteRule ^blog/(.*)$ /$1 [L,NC,R=301]
</IfModule>
This assumes there is no .htaccess in /blog/ directory. However if it is there for some reason then use this rule as first rule in /blog/.htaccess:
RewriteEngine On
RewriteRule ^(.*)$ /$1 [L,R=301]

Rewrite Role does not apply

I have php website and I have created .htaccess file. I have two rules. One for force www and other for permalink.
I want to change following Url
http://www.yatha.tv/play.php?vid=1437&id=1
to
http://www.yatha.tv/1437/1.html
But this rule does not change
RewriteRule ^([^/]*)/([^/]*)\.html$ /play.php?vid=$1&id=$2 [L]
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yatha\.tv$
RewriteRule ^(.*)$ http://www.yatha.tv/$1 [R=301,L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /play.php?vid=$1&id=$2 [L]
</IfModule>

How to make other subdirectory work with cakephp in root?

I have this path in my hosting server with domain http://www.example.com/ and it's running cakephp in the directory home. but now I want my another_project_name appear in browser with http://www.example.com/another_project_name/.
This is my structure :
/www
.htaccess
home/
.htaccess
webroot/
.htaccess
lib/
another_project_name/
This is my /www/.htaccess :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ home/webroot/ [L]
RewriteRule (.*) home/webroot/$1 [L]
</IfModule>
How to configure .htaccess file in /www/.htaccess to make my another_project_name work ?
Try this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (another_project_name/.*) $1 [L] # adjust the regex to what you want.
RewriteRule (another_project_name.*) $1 [L] # adjust the regex to what you want.
RewriteRule ^$ home/webroot/ [L]
RewriteRule (.*) home/webroot/$1 [L]
</IfModule>
.htaccess file should be like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/?(another_project_name)/(.*)$
RewriteRule ^.*$ - [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
For multiple directories
RewriteCond %{REQUEST_URI} ^/?(another_project_name1 | another_project_name2 | another_project_name3 )/(.*)$

1and1 subdirectory cakePHP installation issue

I am deploying my app on a live server hosted on 1and1.co.uk.
I am trying to make it work since 8 and getting crazy, trying with a fresh version downloaded from the cakePHP website.
Here is my configuration.
A subdomain pointing to a directory :
subdomain.mydomain.com => /subdirectory
So I think the first question is, on the view of my app, is that a subdirectory ?
I don't think so but I am not sure.
I tried hundreds of .htaccess configurations, nothing works, I get a 500 error or the following message:
Parse error: syntax error, unexpected '=', expecting '(' in /homepages/41/d201409564/htdocs/hire/lib/Cake/bootstrap.php on line 173
I thought that topic would fix my problem, but still not working.
Thanks for your help
Could fix it finally thanks to : http://www.grafikart.fr/forum/topic/2351
Here is the solution, the trick is probably to enforce the PHP5, even if it's activated on your server (which is my case)
/.htaccess
AddType x-mapp-php5 .php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
/app/.htaccess
AddType x-mapp-php5 .php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/app/webroot/.htaccess
AddType x-mapp-php5 .php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
If someone struggles about this with CakePHP 4.xx, this is how i got it running at IONOS (former 1and1). CakePHP is installed in a Subdirectory:
(Maindirectory)
Subdirectory (CakePHP)
/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
#the next two lines are only for forwarding to https
RewriteCond %{SERVER_Port} !=443
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
# end of forwarding
RewriteBase /
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
webroot/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

rewrite rule for shop in lithium / apache

I have a lithium installation and all the .htaccess works fine.
I need to install OpenCart as a shopping cart in app/webroot/shop
I copied all the files and also changed the .htaccess file in the root folder of lithium installation as
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule shop/(.*) /app/webroot/shop/$1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Still when I browse http://domain.com/shop it takes me to http://domain.com/app/webroot/shop/
With an error on page:
Exception
lithium\action\DispatchException (code 404)
Action `webroot` not found.
Please help me in solving this problem.
You may try this instead:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/app/webroot/shop/? [NC]
RewriteRule ^shop/(.*) /app/webroot/shop/$1 [L,NC]
RewriteCond %{REQUEST_URI} !/app/webroot/? [NC]
RewriteRule ^$ /app/webroot/ [L,NC]
RewriteCond %{REQUEST_URI} !/app/webroot/? [NC]
RewriteRule ^(.*) /app/webroot/$1 [L,NC]
</IfModule>
The problem is that your last "catch all" rule is also redirecting all requests for the shop to lithium, which you don't want.
Try this
Options +FollowSymlinks -MultiViews
RewriteEngine On
# Rewrite all URLs that start with /shop to /app/webroot/shop
RewriteRule ^shop/.? /app/webroot/shop%{REQUEST_URI} [L]
# Rewrite all URLs that don't start with /app/webroot/shop to /app/webroot
RewriteCond %{REQUEST_URI} !^/app/webroot/shop
RewriteRule .? /app/webroot%{REQUEST_URI} [L]

Resources