Redirect subfolder index.php to subfolder root - .htaccess

I have the following url I want redirect using the .htaccess file in root with Mod Rewrite. I have searched and found good examples for the index file in root, but not in subfolder.
This is what I have and what I need.
Thank you in advance for your help.
/folder1/index.php
/folder1/index.php/
to
http://www.example.com/folder1/
/folder2/index.php
/folder2/index.php/
to
http://www.example.com/folder2/
I was asked for only 2 hyperlinks so I removed part of the link on the examples above. I appreciate the shorter way because I have many folders.

Try this in your .htaccess file.
RewriteEngine On
Rewrite ^/folder1/index.php$ /folder1/ [L]
<Directory folder1>
DirectoryIndex index.php
</Directory>
Of course the index can be what every you want like newindex.php.

To redirect /folder/index.php to /folder ,You can use :
RewriteEngine on
RewriteRule ^([^/]+)/index\.php$ /$1/ [NC,L,R]
This will redirect :
/anyfolder/index.php
to
/anyfolder/

Related

Symfony .htaccess rewrite and redirect not working

I know very little about symfony framework. I copied a website www.example.net to www.example.com site works with url www.example.com/www/app.php or even with www.example.com/www/ but I want it to redirect automatically to app.php without showing it in the url. My htaccess in the www (web) directory is as follows:
&ltIfModule mod_rewrite.c&gt
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
&ltIfModule&gt
It doesn't redirect.
Thanks
In your Vhost:
Change this line (Directory section):
AllowOverride None
to:
AllowOverride All
Instead of that rule can you try:
RewriteBase /www/
RewriteRule ^((?!app\.php).*)$ app.php/$1 [NC,L]
Sorry I can't test with Symphony as I am not near my home computer.
A bit late to this game but I just found an Apache directive that saves so much time and makes your htaccess cleaner. The only caveat is you must have Apache 2.2.16+. To have all urls except valid files (images, etc) use app.php as a front controller use the FallbackResource directive.
<Directory "/web/symfony-project">
FallbackResource /app.php
</Directory>

htaccess 301 redirect with wildcard to a single page

We took over a website with about a kabillion pages in the old site root directory done in htm that need to be retired. I want to do a 301 redirect from the pages to the index.php in the root directory of the new site using a wildcard. An example of the page naming structure follows:
oldpage_dees.htm
oldPage_dat.htm
oldPage_deeudderting.htm
and so on. As stated, I need them redirected to the index.php in the root directory. Going by examples and discussions here I've tried:
RewriteEngine On
RewriteRule ^/oldpage_([\w]*).htm$ /index.php [R=301,L]
but I get a 404 error.
Any suggestions? Thanks in advance!
As .htaccess is directory level configuration file, you don't need to specify forward slash, I think this will do the job:
RewriteEngine On
RewriteRule ^oldpage_([\w]*).htm$ index.php [R=301,L]
Meanwhile, you can use the following .htaccess tester to debug your rewrite rules.

htaccess how to redirect all pages in the directory to index page

I want to redirect from all pages to index page in the directory.
And wrong addresses too.
http://site.com/directory/anyword move to http://site.com/directory/index.html
I did in .htaccess RedirectMatch 301 /directory /directory/index.html
But I need except directory/thankyou.html
It does redirect but doesn't open index.html - resulted in too many redirects
May be I can try with 404.
You need to exclude index.html from your match, otherwise you get an infinite loop where directory/index.html redirects to itself over and over.
Unfortunately my knowledge of writing .htaccess files is basically nonexistent so I can't provide an example.
Mod Rewrite?
RewriteEngine On
RewriteCond %{REQUEST_URI} !index\.html$
RewriteRule /directory/.+ /directory/index.html
You can redirect all pages or subdirectory to the index page.,
try this-
root/.htaccess
enter code here
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteRule ^(.+?/)?home/?$ $1/index.php [L,NC]

htaccess RewriteRule for url alias

My website has several files and folders:
mywebsite.com/index.php
mywebsite.com/files/...
Our users asked me if it would be possible to create url alias like this:
mywebsite.com/thisalias -> mywebsite.com/index.php?var=thisalias
With other words: if the folder/file "thisalias" doesn't exist, it should redirect. I have tried several code samples from StackOverflow but for some reason it didn't work on my host. Any suggestions? I'm not really good with .htaccess coding.
I believe this is what you are looking for.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/([a-zA-Z0-9]+)$ index.php?var=$1 [L]
</IfModule>

htaccess rewrite rule similar to WordPress

Ok I have a script in the folder 'intake'. The index.php file auto creates a list of urls. Those urls are in the format:
/intake/4/Westrop
I have an .htaccess file in the intake folder. I want it to redirect the url to a FILE.
The above example would then become /intake/redirect.php?id=4&name=Westrop
Here's what I have so far:
DirectoryIndex index.php
Options All -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/(.*)$ /intake/redirect.php?id=$1&name=$2 [L]
</IfModule>
But for some reason if I type /intake or /intake/index.php I get a 404 error. According to firebug its trying to take "intake" and turn it into "intake.php"
Any ideas?
Place the following code in .htaccess file in website root folder:
RewriteEngine On
RewriteRule ^intake/(\d+)/([a-z0-9\-_]+)$ /intake/redirect.php?id=$1&name=$2 [NC,QSA,L]
P.S.
Do not use this sort of pattern -- ^(.*)/(.*)$ -- in your case for longer URLs it will work not as you would expect. It will match your URL .. but in a wrong way.
Start your .htaccess with this option:
Options +All -MultiViews -Indexes

Resources