I have some folders in root of my server:
css/
js/
gfx/
new_www/
...
and some more. Assuming that I want in folder new_www copy of current page, but force it to use some things from root folder (for example gfx folder). I've tried following with .htaccess but its not working:
RewriteEngine on
RewriteBase /
RewriteRule /new_www/_js/(.*) /_js/$1 [L]
RewriteRule /new_www/gfx/(.*) /gfx/$1 [L]
What am I doing wrong? .htaccess is placed in root of folder.
Please understand that RewriteRule doesn't match leading slash in an URI when used in .htaccess. Your code should be replaced with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^new_www/(_js/.*)$ /$1 [L,NC]
RewriteRule ^new_www/(gfx/.*)$ /$1 [L,NC]
OR even better will be to have just one rule like this:
RewriteRule ^new_www/(.+)$ /$1 [L,NC]
Related
I have site e.g. 123.123.123.123/subdirectory/ and I would like to rewrite
123.123.123.123/subdirectory/page/123
to
123.123.123.123/subdirectory/page.php?id=123.
I've created .htaccess file:
RewriteEngine On
RewriteBase /subdirectory
RewriteRule ^page/(.*)$ page.php?id=$1 [NC,L,QSA]
but it doesn't work (rewriting in on).
Use this rule and it will work.
RewriteRule ^123\.123\.123\.123/subdirectory/page/123$ /123.123.123.123/subdirectory/page.php?id=123&%{QUERY_STRING}
I have a site like "abc.com/1_en-Application.html . Now i want to change it to abc.com/application.html.
I have .htaccess like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([0-9]+)-([0-9]+)_(.*)-(.*).html$ index.php?id=$1&page=$2&lang=$3 [L]
RewriteRule ^([0-9]+)_(.*)-(.*).html$ index.php?id=$1&lang=$2 [L]
</IfModule>
Please help me how can i do this ?
Add the 3 lines below the existing rewrite rules:
RewriteCond %{REQUEST_URI} /application.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^application.html$ index.php?id=1&lang=en [L]
If you don't have a real file called application.html in the web root directory, this will rewrite the URL and internally direct it to index.php
If application.html is a real file, it will be shown instead. In that case, the 3 lines will still work but not necessary to include.
Since 2 days I have been trying to get my cake app working (using German 1&1 hosting). The desired address is: http://www.bzalewski.de/k/front. If you open it, you can see, it's there but without images and css. Also this: http://www.bzalewski.de/k/front/art/discover doesn't work (but it does locally with XAMPP. There is no routing, just ArtController --> public function discover()).
I followed the instructions from this article: http://bakery.cakephp.org/articles/tim_m/2007/09/20/500-errors-with-1and1-hosting-apache-1-x
My three .htaccess look like this:
./.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ /k/front/app/webroot/ [L]
RewriteRule (.*) k/front/app/webroot/$1 [L]
</IfModule>
./app/.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ /k/front/app/webroot/ [L]
RewriteRule (.*) /k/front/app/webroot/$1 [L]
</IfModule>
.app/webroot/.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /k/front/app/webroot/index.php?url=$1 [QSA,L]
</IfModule>
I would appreciate any help to:
make controllers work (art/discover working)
make images and other stuff in the webroot directory work
Just to mention it: my local XAMPP installation works with standard .htaccess files without any problems.
Try adding this line in the root .htaccess (the htaccess in /k/front/ folder) after RewriteEngine On:
RewriteBase /k/front/
Edit : I did not see that you put /k/front/ everywhere in the htaccess
Then add RewriteBase / with you version of the htaccess
OR add RewriteBase /k/front/ with the default htaccess (without /k/front/ in the RewriteRules )
I actually thought there should already be a thread about this but i wasn't able to find one.
let's say i have a website with this structure:
/index.php
/.htaccess
/template
/template/css
/template/css/foo.css
I'm redirecting everything to index.php with .htaccess
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]
Now I've got a problem with the css. that i could fix by placing another .htaccess in /template with this
RewriteEngine off
Options -Indexes
And then access the css file with http://example.com/template/css/foo.css but actually i would prefere to have just http://example.com/css/foo.css
So i tried to put in /.htaccess the following code (that didn't worked). What did i do wrong?
RewriteEngine on
RewriteBase /
RewriteRule ^/css/(.*) www/css/$1 [L]
RewriteRule ^/js/(.*) www/js/$1 [L]
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]
note I don't have any .htaccess in /template!
You should remove the htaccess file in the css folder. You just need to exclude rewrites to the template directory. You can do it all in a single file:
RewriteEngine on
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/template/%{REQUEST_URI} -f
RewriteRule ^(.*)$ /template/$1 [L]
RewriteCond ${REQUEST_URI} ^/template/
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]
The first rule handles requests for the css directory, and the second rule is the one you had that routes to index.php except if the request is for template.
I am pretty new to Apache.
Consider I have URL like http://www.abc.com/home
I want this URL to be redirected to http://www.abc.com/foo/home.
Basically, I want to add "foo/" to URL if not present. How would I achieve this?
You may try this in one .htaccess file at root directory:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/foo [NC]
RewriteRule ^home/(.*) /foo/home/$1 [L,NC]
For permanent redirection, replace [L,NC] with [R=301,L,NC]