Jump to content

Recommended Posts

In the past I had the following code to remove the "index.php" portion of a URL to transform this "www.domain.com/index.php" to this "www.domain.com/"

This is what I used...

	RewriteCond %{REQUEST_URI} ^.*/index\.php
	RewriteRule ^(.*)index.php$ $1 [L,R=301]
	

 

 

This seemed to work okay, but ow i have expanded my temporary website.

 

Now I have the following set up...

	www.company.com/index.php
	www.company.com/news/news-index.php
	www.company.com/news/economy/economy-index.php
	

 

What I want in the address bar is this...

	www.company.com/
	www.company.com/news/
	www.company.com/news/economy/
	

 

I tried modifying the above cod eliek this, but something I did - not sure what - ending up giving me very weird page loads where iw as seeing a directory listing, and I ultimately had to comment out my code and reboot?!

 

What do I need to do to fix things?

I have tis original code...

	RewriteCond %{REQUEST_URI} ^.*/index\.php
	RewriteRule ^(.*)index.php$ $1 [L,R=301]
	

 

and then I tried adding this a few lines down...

	RewriteCond %{REQUEST_URI} ^.*/news-index\.php
	RewriteRule ^(.*)news-index.php$ $1 [L,R=301]
	 
	RewriteCond %{REQUEST_URI} ^.*/economy-index\.php
	RewriteRule ^(.*)economy-index.php$ $1 [L,R=301]
	

 

Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/312016-rewriting-indexphp-and-news-indexphp/
Share on other sites

2 hours ago, SaranacLake said:

Now I have the following set up...


	www.company.com/index.php
	www.company.com/news/news-index.php
	www.company.com/news/economy/economy-index.php
	

Use index.php for all three of them.

16 hours ago, requinix said:

Use index.php for all three of them.

I had started to do that, but realized it was really confusing when I had several tabs open in NetBeans that all said "index.php"

So what was wrong with my mod_rewrite above?

 

8 minutes ago, requinix said:

Nothing was wrong with the rewriting... I think. Nothing that I remember seeing, at least.

The rewriting isn't responsible for the directory index - the fact that your files are not called "index.php" is.

A-ha...

So I think you are saying that my instance of MAMP is expecting that every directory has an "index.php" file in it?

Can I disable that feature?

I understand your suggestion to have all of my files be "index.php", but as mentioned, it makes working with them in NetBeans to be a pain.  And the last thing I need to to spend a bunch of time updating a file only to find out it is the wrong "index.php"?!

(Once I get my "real" website up and running, this is less of an issue since that one is database driven.  But for my temproary site, I am just using straight-up hard-coded php files with not databse.)

So can I turn of the requirement that every directory needs an "index.php" file?

And if I do that, are there any downsides?

 

1 hour ago, requinix said:

Sure, but the result is that instead of getting a directory index you're going to get a 403 Forbidden page. So that's not going to help.

If I recall correctly, you could just insert a 'dummy" index.php file in every directory, right?

 

Currently I have this code in my .htaccess in the public_html folder...

	Options -Indexes
	 
	ErrorDocument 403 "/utilities/access-denied.php"
	

 

Shouldn't that first line of code have prevented getting a directory listing like I was seeing when i renamed "index.php" to "news-index.php"?

 

And wouldn't that second line handle the 403 error if I made whatever change I need to not require the "index.php" as the default file in every directory?

 

I honestly don't recall how I broke things this weekend - i had like 20+ tabs open and was doing a little of everything trying to get this site up.  But I know the directory listing threw me off, and now that i think about it, it seems to me that I WAS getting a 403 error because I couldn't figure out a way to test out my "access-denied.php" error-handling file, and then I accidentally caused a 403.

I do know that I had to reboot to get things to behave normally.

 

At any rate, with the code I listed above, what do i need to do if...

1.) I want to make "news-index.php" the default file in the "news" folder?

2.) How can I make my URL pretty and so

"http://www.domain.com/news/news-index.php"

 will be rewitten as 

"http://www.domain.com/news/"

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.