473,890 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re-write index.php to /home/ using htaccess

134 New Member
Hi

i m using htaccess to rewrite my urls.,

In this instead of http://www.mysite.com/index.php i want the url as http://www.mysite.com/home/

any ideas??

and also i m using the following code to redirect to the http://www.mysite.com/index.php when a non-existing filename is typed..

Expand|Select|Wrap|Line Numbers
  1. .........
  2. .............
  3. RewriteCond %{REQUEST_FILENAME} !-f 
  4. RewriteCond %{REQUEST_URI} !^/Admin 
  5. RewriteRule ^ http://www.mysite.com/index.php
  6.  
  7.  
so i want the url to be displayed as http://www.mysite.com/home/ whenever http://www.mysite.com/index.php is called..And at the same time when an non-existing filename i,e url is passed it must be redirected to http://www.mysite.com/home/ instead of http://www.mysite.com/index.php


regards
vijay
Sep 13 '08 #1
6 8921
Atli
5,058 Recognized Expert Expert
Hi.

You should simply look for "index.php" and redirect it to "/home/".
Using the [R] option will cause a redirect, which will cause the URL to change in the user's browser.

That should be as simple as:
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^index\.php$ /home/ [R]
  2.  
Sep 13 '08 #2
vjayis
134 New Member
Hi.

You should simply look for "index.php" and redirect it to "/home/".
Using the [R] option will cause a redirect, which will cause the URL to change in the user's browser.

That should be as simple as:
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^index\.php$ /home/ [R]
  2.  


Hi

tried by placing it but page results by displaying the error message as

""
This webpage has a redirect loop.

The webpage at http://www.mysite.com/home/ has resulted in too many redirects
""

i think it may be due to the rewirte rule i hav placed for the non existing file or urls
Sep 13 '08 #3
Atli
5,058 Recognized Expert Expert
Yea, that last rule in your code doesn't look quite right.
If I put that into the .htaccess file on a project I'm working on now I also get the "to many redirects" error.

Try removing that, see what happens.
Sep 13 '08 #4
vjayis
134 New Member
tried and it also results in an error which says that

"
Oops! This link appears broken.
HTTP 404 - File not found.

"
Sep 13 '08 #5
Atli
5,058 Recognized Expert Expert
Ok.

That may cause a problem, because re-directing back and forth like that ends up causing an indefinite loop.

There is a far easier solution, if you want.

Because index.php is an index file, if you simply specify the directory that contains the file, it will be executed.
In your case, that is the root directory.

So rather than showing example.com/home/ it would just show example.com/.
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^index\.php$ / [R]
  2.  
That way, you don't need to redirect the /home/ directory back to the index file and enter a loop. The index file would be automatically executed.

And if you want all non-existing files to go there as well, you could catch the 404 error and show the the index file, which would be re-directed like a normal link:
Expand|Select|Wrap|Line Numbers
  1. ErrorDocument 404 /index.php
  2.  
Sep 13 '08 #6
vjayis
134 New Member
Hi

thanks for ur help., and it works good.,

but the rewrite rules written for index.php gets changed., and no probs i can get rid of it..

but i need it to be displayed as http://www.mysite.com/home/ instead of http://www.mysite.com/

anyother way ???
Sep 13 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4326
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would be better to promote better programming than rely on PHP to compensate for lazy programming?
4
6436
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
1
4105
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR>
11
4022
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
18552
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function blocks until something.exe terminates. Just what I /don't/ want. (Wouldn't an & be nice here! Sigh) I need something.exe to disconnect and run in the background while I
1
3708
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with sockets??
8
4423
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an image, which will upload the record to a mySql db so users can then either view all profiles or query.. I.e. show all males in UK, all femails over 35 etc. Now, I'm not asking for How to do this but more what would be the best way? I've looked at...
1
3642
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id NOT IN ( SELECT manufacturers_id FROM products )
2
5319
by: JW | last post by:
I wanted have this as part of a flood control script: <? echo ("Flood control in place - please wait " . $floodinterval . " seconds between postings."); sleep(5); // go back two pages echo "<script>window.history.go(-2);</script>"; exit; ?>
2
3348
by: Frans Schmidt | last post by:
I want to make a new database with several tables, so I did the following: <?php CREATE DATABASE bedrijf; CREATE TABLE werknemers (voornaam varchar(15), achternaam varchar(20), leeftijd tinyint(3), adres varchar(30), woonplaats varchar(20),
0
9970
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11207
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10794
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10896
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9612
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.