SaranacLake Posted January 17, 2021 Share Posted January 17, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/312016-rewriting-indexphp-and-news-indexphp/ Share on other sites More sharing options...
requinix Posted January 18, 2021 Share Posted January 18, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/312016-rewriting-indexphp-and-news-indexphp/#findComment-1583832 Share on other sites More sharing options...
SaranacLake Posted January 18, 2021 Author Share Posted January 18, 2021 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? Quote Link to comment https://forums.phpfreaks.com/topic/312016-rewriting-indexphp-and-news-indexphp/#findComment-1583853 Share on other sites More sharing options...
requinix Posted January 18, 2021 Share Posted January 18, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/312016-rewriting-indexphp-and-news-indexphp/#findComment-1583860 Share on other sites More sharing options...
SaranacLake Posted January 18, 2021 Author Share Posted January 18, 2021 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? Quote Link to comment https://forums.phpfreaks.com/topic/312016-rewriting-indexphp-and-news-indexphp/#findComment-1583863 Share on other sites More sharing options...
requinix Posted January 18, 2021 Share Posted January 18, 2021 1 hour ago, SaranacLake said: Can I disable that feature? 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. Quote Link to comment https://forums.phpfreaks.com/topic/312016-rewriting-indexphp-and-news-indexphp/#findComment-1583876 Share on other sites More sharing options...
SaranacLake Posted January 18, 2021 Author Share Posted January 18, 2021 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/" Quote Link to comment https://forums.phpfreaks.com/topic/312016-rewriting-indexphp-and-news-indexphp/#findComment-1583887 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.