Apache redirect directory to index.php - apache

I'm trying to redirect a simple folder to /folder/index.php.
My URL looks like this : site.com/folder and I want site.com/folder/index.php.
Throught de web I only found the reverse way but I do want to see my index.php so that I can later use links like site.com/folder/index.php#344
My .htaccess located in /folder/ looks like this :
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/(.+)$ index.php
</IfModule>
And of course it doesn't work.
Maybe is apache ignoring my file ? Maybe some others .htaccess are interfering ? I have no idea since I'm new to apache...
Thanks for your help

You could just skip this mod_rewrite stuff and use mod_dir:
DirectoryIndex index.php
With that in the htaccess file in /folder, going to http://site.com/folder you will get served the contents of index.php.

Related

How To Use Htacess for www.example.com/type.php?user=name

I want to redirect www.example.com/type/name to www.example.com/type.php?user=name
{
RewriteRule ^([a-zA-Z0-9_-]+)/type$ type.php?key=$1
RewriteRule ^([a-zA-Z0-9_-]+)/type/$ type.php?key=$1
}
Please help me about this.
Try adding this to the .htaccess file in your web document root folder (often public_html or htdocs):
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^type/([^/]+)/? type.php?key=$1 [L]
This assumes that mod_rewrite is both installed and activated for .htaccess files. If you are not sure, to check if mod_rewrite is even installed, look at the list of installed modules in the output of phpinfo(); By default, mod_rewrite is not enabled for .htaccess files. If you are managing your own server, open httpd.conf and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All
try this , hope it helps :
RewriteBase /www.example.com
RewriteEngine On
RewriteRule ^type/(.*)/$ /type.php?user=$1
#OR
RewriteRule ^(.*)/(.*)/$ /$1.php?user=$2
PS : The first one works only for the url : www.example.com/type/value ,the second one works for any page in your site ex: www.example.com/anypage/value

htaccess rule without noticable redirect

i have the following redirect rule
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^$ /folder/
basically my index.html file is in folder.html and instead of copy and pasting the index.html file from /folder/ i was trying to use the rule above to request the file and output the file as mysite.com but instead it is redirecting to mysite.com/folder/index.html. I assume this is possible to do as frameworks use the rewrite rule and this doesn't redirect the browser. Can anyone advise on what i am doing wrong?
Thanks in advance.

Remove '/home' directory from URL

People i got 'www.domain.com/home'. I want delete from name '/home'. Just on url should left 'www.domain.com'.
I tested .htaccess but this not works. I see server automatic delete 'index.html' from URL. Some rules works in my htaccess but the replacing a names in URL - not.
Somebody know how to delete '/home'? I just spent all morning to find solution, but nothing working...
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
RewriteRule ^home/?$ / [L,R=301,NC]

Htaccess redirect or rewrite

I'm in the process of testing a site at a preview URL until the DNS transfers over. I'm previewing the site at http://IP_ADDRESS/~name/.
All of my images that have been uploaded in the CMS are listed like <img src="/uploads/images/">.
But this doesn't work while i'm on the preview URL. So ideally I need to redirect /uploads/* to /~name/uploads/*
I was wondering if this should be a redirect or a rewrite in htaccess and what the rule might be?
Thanks.
This is the code you'll need in your .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^uploads/ ~name%{REQUEST_URI} [L,NC]

apache mod rewrite

Need some help with a rewrite please.
I have domain http://www.example.com. There are multiple folders within the root. I'd like to rewrite http://www.example.com/folder1/public/index.php to http://www.example.com/folder1
I dont have access to the main apache config so i'll need to do this in a .htaccess. If possible I'd also like to place the .htaccess inside folder1, not in the root.
Any help would be awesome, thanks.
Thinking monkey is close. Try:
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteBase /folder1
RewriteRule ^(?!public/)(.*) public/$1 [L]
You need the RewriteBaseand you need to stop recursive evaluation of the rule. The (?!public/) bit just means don't match anything already starting with public/. You need this sort of guard in .htaccess rules.
I presume you are trying to redirect any request to folder1 to folder1/public.
By that I mean, you want your URLs to look like http://www.example.com/folder1 while the actual URL will be http://www.example.com/folder1/public/index.php.
First of all, you have to use http://www.example.com/folder1 in your hrefs and rewrite this to http://www.example.com/folder1/public/index.php.
Add the below to your .htaccess residing in your folder folder1.
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]