htaccess for separate folder without disturbing homepage - regex

I have wordpress installed in rootfolder in http://example.com . I have created new folder named world http://example.com/world , I need htaccess to work on that particular folder alone , Is it possible?
My htaccess I need to use for folder world is given below. I added this in rootfolder htaccess and I got internal server error and hence I don't want to disturb the root folder.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*)(\/?)$ / [QSA,NC,L]
My root folder htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Replace your DOCUMENT_ROOT/.htaccess with this code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# don't do anything for /world folder
RewriteRule ^world/ - [L,NC]
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Replace your DOCUMENT_ROOT/world/.htaccess with this code:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /world/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php [L]

Related

How to redirect everything but an specific path on a htaccess file?

I'm trying to create an htaccess file so that everything gets redirected to the root of the site except for an specific path /api/date.
I have this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I've made some research on javascript regex and it seems that it is not possible to exclude words. So it is possible to do this here? How?
Thanks!
Try with below we are excluding /api/date and passing everything apart from that.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!(\/api\/date)$).+$ /index.php [L]
</IfModule>

rewrite rule check for string existence

i need a RewriteRule which changes an url of http://domain.org/foo/bar to http://domain.org/de/foo/bar but does nothing if there is an url like http://domain.org/en/foo/bar or http://domain.org/de/foo/bar
so if there is no en/ and no de/ then it should add de/, else it should do nothing
how can this be done? i already played around a bit with regex, but I dont know how to check if there is en/ or if there is no en/.
help is highly appreciated.
UPDATE:
my current rules are the default rules you should have when running wordpress:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
UPDATE2:
this is wordpress and de/ and en/ are not actual folders.. they are used by a multilanguage plugin. since i have some issues with this plugin i need the redirect as described above.
In general without any other rules, this would redirect anything that doesn't start with /en/foo/bar.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/en [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /de/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
You can use this rule in your root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!(?:en|de)).*)$ de/$1 [L,NC,R]
Keep this rule before default WP rule.
EDIT Full .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!(?:en|de)).*)$ de/$1 [L,NC,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Rewrite codeigniter URL with htaccess

I need to rewrite the URL by Apache mod-rewrite in Codeigniter
The page name is example.com/pages/page1
and i need to rename it by example.com/welcome.html
I wrote this rules in htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pages/page1$ welcome.html [PT,L]
It doesn't work. How can i do that?.
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^sys.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^app.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
assumming that index.php is your index page.
and change in config.php
$config['index_page'] = '';

htaccess human readable

I have a site which already defined htaccess for making url nice
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
Options -indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php
Everything works fine (there is cms in the root folder).
Now I want to create a folder inside root and make another rules for it:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
Options -indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !tip [NC]
RewriteRule (.*) index.php [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^tip/([^/]+)/? /tip/?id=$1
So I want to redirect everything from url: .../tip/?id=N -> ../tip/N
It seems to work fine, id is passed, data is loaded BUT. All the urls are wrong inside site (javascript, css). They aren't loaded.
Look at: http://wincode.org/tip/3
For example, code: <script defer src="js/filtrify.js"></script> produces: http://wincode.org/tip/js/filtrify.js but if you will try to load it in another tab, it will pass js/filtrify.js as id argument, I think. How to fix this?
A. Change your .htaccess code to this in $DOCUMENT_ROOT/.htaccess:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
Options -indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (?!^tip(/.*|)$)^.*$ /index.php [L,NC]
B. Change your .htaccess code to this in $DOCUMENT_ROOT/tip/.htaccess:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /tip
Options -indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^/]+)/?$ /tip/?id=$1 [L,QSA]
I just improved little bit anubhava reply, this one is based on root folder example, but you can use same approach for other dir that you need.
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options -indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (?!^tip(/.*|)$)^.*$ /index.php [L,NC]
</IfModule>
<IfModule !mod_rewrite.c>
# Mod_rewrite not installed, redirect all 404 errors to index.php.
ErrorDocument 404 index.php
</IfModule>

How can I rewrite this URL using .htaccess

How can I rewrite this URL
http://staging.felgenexklusiv.de/?felge=asa-gt1
to be displayed like this?
http://staging.felgenexklusiv.de/felge/asa-gt1
This is my existing .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Just before </IfModule> insert these lines:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:index\.php|)\?(felge)=([^\s&]*) [NC]
RewriteRule ^ %1/%2? [NC,L,R]
RewriteRule ^(felge)/(.*)/?$ /?$1=$2 [NC,L,QSA]
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([a-zA-Z]+)/([a-zA-Z0-9\-]+)?/?(.*)$ index.php?partie=$1&name=$2&%{QUERY_STRING} [L,QSA]
</IfModule>