if there is no index file in the folder how do i rewrite an index file from another folder...so for example the main site has two folders like this
main_folder/no index.php
folder1/index.php
folder2/index.php
what do i have to put in the rewrite rule to make the main page show the index for folder1/index.php
EDIT
got it working with this
RewriteEngine On
RewriteCond %{HTTP_HOST} site.com
RewriteCond %{REQUEST_URI} !folder1/
RewriteRule ^(.*)$ folder1/$1 [L]
Try this:
#in the .htaccess file where there is no exit or in root
Options Indexes #if still fails delete this line
DirectoryIndex /folder1/index.php
Not sure though
edit: for sub levels maybe adding this solves.
RewriteCond %{REQUEST_URI} ^/folder1/
RewriteRule ^(.*)$ http://www.example.org/$1 [L]
do you just want a redirect?
Redirect 301 / /folder1/index.php
Related
I have to upload a directory by default when someone comes to my static website
this is the structure
under my public_html I have domain folder 'domainname'. In domain folder I've webfolder/fr/index.html
I want to load files under webfolder/fr directly. following is my .htaccess under the domain name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domainname$ [NC,OR]
RewriteCond %{HTTP_HOST} ^domainname$
RewriteCond %{REQUEST_URI} !webfolder/fr/
RewriteRule (.*) /en/$1 [L]
if I remove fr/index.html it loads files under webfolder. If I set
RewriteCond %{REQUEST_URI} !webfolder/fr/
it gives 500 internal error.
Please help me how can I fix this.
To Clarify:
When I open my domain www.domain.com I want it to open www.domain.com/webfolder/fr
Please add following two lines to allow a specific file to load just in case there is no default index file setup already
Options -Indexes
DirectoryIndex index.html index.php
Note : if you have to load first php index file then you have set like
DirectoryIndex index.php index.html
So you want to redirect your domain from root folder to some other subfolder
try this code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domainname$ [NC,OR]
RewriteCond %{HTTP_HOST} ^domainname$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) /webfolder/fr [L]
hope this code will work for you
optional:-you can also do this by changing your home directory in cpanel settings
I'm trying to relocate a site into a temporary folder in order to install a CMS in the root. The redirect works but all the internal links in the site now take me back to the index page in the temporary folder. The .htaccess in the root is as follows:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/old/ [R=301,NC]
it's because you're redirecting everything to the new url. You should put something like this:
RewriteRule ^$ http://www.example.com/old [R=301,NC]
RewriteRule ^(.*)$ http://www.example.com/old/$1 [R=301,NC]
PS: The $1 take the arguments in expression
PS2: You should not use code 301 for a temporary redirect, the 302 is more appropriate https://en.wikipedia.org/wiki/HTTP_302
I have this in my html folder
--html
--.htaccess
--app
--application_name
--public
--index.php
--landing_page
--index.php
As of now, everytime the website url is accessed (www.website.com), the browser opens the landing_page/index.php.
How can I make it that when I access www.website.com/beta, I will be doing a request to html/app/application_name/public/index.php
I have tried adding this to the .htaccess
RewriteRule ^beta/?$ app/application_name/public/index.php [L,NC]
This is the whole .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^beta/?$ app/application_name/public/index.php [L,NC]
But it does not work. Not sure what term to use to search for this kind of problem.
Your root is currently set at /html, and therefore the RewriteBase / is at /, the /beta/ simply does not exist. You could change the RewriteBase /app/application_home/public/ and set the RewriteRule ^beta/?$ index.php [L,NC]. This however no longer give you the access to the landing page, not sure if this is what you want?
I am trying to redirect all calls to mysite.com/api/foo/bar/json?param1=1... to mysite.com/api
I've tried
RewriteEngine On
RewriteRule "^api/?(.*)" "/api" [R=302]
But it doesn't work because it redirects in a loop
You need to exclude the destination path you are redirecting to
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/api/?$
RewriteRule ^api/?(.*) /api [R=302]
First check file permission maybe you don't have to made edit on the .htaccess file. Then insert this line of code.
RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
I would like to rewrite all index files like /index in my subdomain as well as in my domain. Up to this point there was no need to use a subdomain. Now the problem is a rewrite rule from the htaccess file. This rewrites the URL as in the given code below:
RewriteRule ^index\.(htm|html|php) http://%{HTTP_HOST}/ [R=301,L]
RewriteRule ^(.*)/index\.(htm|html|php) http://%{HTTP_HOST}/$1/ [R=301,L]
Means that in the domain all index files will be rewritten. This works well but not in the subdomain. Now I thought I can simply add a condition for my subdomain like:
RewriteCond %{HTTP_HOST} !^subdomain\.example\.com$
RewriteCond %{HTTP_HOST} !^www\.
but this fortunately does not work.
To give further information here is what a URL looks like:
http://www.example.com/index
and the subdomain:
http://subdomain.example.com/index
With the code above the URL will be:
http://www.example.com/
and the subdomain:
http://subdomain.example.com/index
It would be great if someone could help me out.
Thanks alot.
UPDATE:
To give further information I need to explain how things work.
In the root dir there is the folder for the subdomain.
--> /index.php
--> /folderA
--> /subdomain
/root --> /folderB
--> /index.php
The URL´s look like that:
http://www.example.com/subdomain/folderA/index
and
http://subdomain.example.com/folderA/index
I do use clean URL´s so that it is just index and not index.php etc.
Default settings already hide index.php when calling a page. The problem will be when I will change the languages what means folderA and folderB. Therefor I read out the basename of the file and use header function to redirect to the right dir. The main problem is the subdomain. In the domain it works well. Just when I have a index page from a folder with the URL:
http://subdomain.example.com/folderA/(index will be hidden)
and will read out the basename (=>index) and will header to:
http://subdomain.example.com/folderB/(index will be hidden)
it will be caused a problem. The URL will be rewritten in a wrong way. Or another simple example:
Having a logo button on all pages in root/subdomain/folderA/
This button is a link with just: .... The page URL will be: subdomain.example.com/folderA/filexy when clicking that link the URL will be rewritten to www.example.com/subdomain/folderA/
Have your rules like this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# do nothing if subdomain
RewriteCond %{HTTP_HOST} !^subdomain\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule - [L]
RewriteRule ^index\.(htm|html|php) http://%{HTTP_HOST}/ [R=301,L]
RewriteRule ^(.*)/index\.(htm|html|php) http://%{HTTP_HOST}/$1/ [R=301,L]
PS: Though I suggest taking a look at DirectoryIndex directive and then you can replace above code with this line:
DirectoryIndex index.htm index.html index.php
Try this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^subdomain\.example\.com$ [NC]
RewriteRule ^/index\.(htm|html|php)$ http://%{HTTP_HOST}/$1 [NC,R=301,L]
</IfModule>