URL 404s looking for index.php in a subdirectory (.htaccess) - php

Hey I am trying to link to a subdirectory and have index.php in that directory load, but it is returning a 404 not found error. The file structure is this:
| index.php
| .htaccess
| subfolder
| index.php
| about.php
When I go to mysite.com/subfolder, I want the index.php there to load. I know the problem is with my .htaccess file because when I remove it the URL works. Here is the code in .htaccess:
Options +MultiViews
# Remove file extensions from page names
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Disable Index Listing
Options -Indexes
My guess is that because I'm removing file extensions, the server is looking for mysite/subfolder.php and can't find it so it 404s. I'm new to .htaccess files, however, and they're still very cryptic to me. Searching online has a lot of code but doesn't explain how anything works. Any ideas on how to fix this issue and why the fix works would be helpful!

If you are enabling MultiViews option then you don't need a rewrite rule to handle extensions.
Just keep these lines in your .htaccess:
Options +MultiViews
DirectorySlash On
DirectoryIndex index.php
And remove everything else. Then test with mysite.com/subfolder/ URL

Related

Htaccess URL Rewriting [GET doesn't works]

In my site I use "show.php?cat=1" type URLs. I want to change for SEO optimization this link types.
I have tried before but I can't understand how to do that.
# Root Host
-- Project Folder
--- index.php
--- show.php
--- css/js/ and other folders
My first purpose is change my links
show.php?cat=1 to show/1/
my code is
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/show/(.*)$ show.php?cat=$1 [QSA,L]
But it doesn't work. I have a GET error. What's wrong?
And my css files gone to /show/css URL
I'am very angry, my css files gone but Get function doesn't work.
Thanks for help.
Edit: If I change show code to 'test' like that, page becomes 404. Why?
Note: I'am using WAMP Server 3, Apache Rewrite_module is working.
RewriteRule ^/test/(.*)$ show.php?cat=$1 [QSA,L]
"The requested URL /project1/test/1 was not found on this server."
Use:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^show/(.*)$ show.php?cat=$1 [QSA,L]
Without first / in htaccess RewriteRule pattern

Apache Rewrite returns nothing at all in subdomain

I've deployed my website on OVH and I have some issues. It works just fine on localhost and it returns nothing on OVH. Both have the same file structure :
/
www/
portfolio/
[others files or folder]
.htaccess
index.php
The problem is that I'm using the Apache's rewrite_mod. I have this in my .htaccess file :
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
So everything goes through index.php but I've got litteraly nothing in return. even if I do a simple echo 'Hello World !' on the first line. Right now I simply try to access it via www.domain.com/portfolio, I didn't use the DirectoryIndex in a www/.htaccess file.
Do you have any idea ? Thank you
Make sure to allow .htaccess in your Apache config. Change AllowOverride None to AllowOverride All

WordPress not working with .htaccess

Have been around the houses with this - have read many htaccess issues etc - and still can't seem to get this to work.
I have a WordPress site installed at var/www
I wanted to have a specific URL point to a specific page. Started by browsing some WordPress plugins. None of them worked so I just went straight to the source and started editing the .htaccess file in the root of the WordPress installation. This is where it started getting frustrating.
One of the many attempts at an .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
Redirect 301 /redirect-me http://my-wordpress-site/?page_id=15
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
All attempts at a Redirect have resulted in 404 Not Found errors.
I have asserted the following things:
Apache2 Rewrite Module is enabled
www-data has both read and write access to the .htaccess file.
AllowOverride is set to All in the apache2.conf file for the directory
Here's a big clue for you: swapping the last ReWrite rule within my .htaccess file does absolutely nothing to my WordPress site...
RewriteRule . /poo.php [L]
Any other suggestions for debugging a failing .htaccess file?
When you make configuration changes such as AllowOverride in the config, make sure your do a restart on Apache2 so the changes become effective. Give that a shot.

Concrete5 project throws 404 on all pages except index.php

I just copied a concrete5 project over to my local box and am trying to get it running on localhost. I had permissions problems at the start so I just ran a sudo chmod 777 -R site which remedied that. I then had problems with clicking a link. Anything besides index.php would result in a 404. So I messed around with the htaccess file. It came in this state:
# Use PHP53 as default
AddHandler application/x-httpd-php53 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php53/lib
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
and I changed it to this:
# Use PHP53 as default
AddHandler application/x-httpd-php53 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php53/lib
</IfModule>
<Directory>
AllowOverride All
</Directory>
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
Now, none of that helped. I decided to just disable pretty URLs in the database. I did that and most links work. It looks like some still don't (maybe the ones that are involved in a package. I don't know because I am picking up this project where someone left it). Bear in mind this all works perfectly on the live server at this time with the first .htaccess file I showed.
Any idea as to how to remedy this?
It does sound like you are having an issue with Pretty URLs. The ones that are still not working after you disabled it are likely do cached items like blocks. If you clear you cache your site will likely work without Pretty URLs turned on.
As for why Pretty URLs are not working, I would first make sure that mod_rewrite is enabled. Then you can try a couple of these for the rewrite rule.
RewriteRule ^(.*)$ index.php [L]
RewriteRule .* index.php [L]
Note: you can use the scripts from your admin login to update "pretty URLs". One caution would be is that if you use .htaccess for another purpose on your site.
Try removing the htaccess completely. Rather than deleting it, rename it. Then get into the dashboard directly at /index/dashboard/ , disable pretty urls, disable and clear the cache, and clear your browser cache.
(In general, always disable pretty urls and disable and clear the cache before cloning a site.)
Once everything is working without pretty urls, you can then start re-enabling.
I've just hit this one whilst trying out concrete5 on my home machine (linux/apache).
In my case, the problem appears to have been because I'd installed concrete5 two directory levels beneath the document root (/var/www/html). Initially, I just created the .htaccess file based on the values given when I enabled pretty urls, then hit the "page not found" problem (couldn't even log in.) Eventually, the penny dropped: I edited .htaccess and changed RewriteRule to point to the actual location of the concrete5 index.php relative to /var/www/html.
So in my case, concrete5 is installed into /var/www/html/playpen/public_html - so the new RewriteRule reads:
RewriteRule . playpen/public_html/index.php
and that appears to work.
Hope it helps someone ...

mod_rewrite to serve a new version of existing files

I have just made a central dynamic script to replace a messy folder full of static files. However, I would like to preserve the old URL's without having to delete those files. Let me give you an example:
I have the following files:
/oldpages/projekt1/index.html
/oldpages/projekt2/index.html
/oldpages/projekt3/index.html
The actual new urls are:
/newscript/script.php?name=projekt1
/newscript/script.php?name=projekt2
/newscript/script.php?name=projekt3
The rewrite rule is:
Options -MultiViews -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^oldpages/([A-Za-z0-9_\-]+)/(index.html)?$ /newscript/script.php?name=$1 [L,QSA]
However, whenever I try to access http://mydomain.com/oldpages/projekt3/index.html it just keeps giving back the old files. After googling, everyone said that multiviews may be the culprit, but apparently, that's not fixing it.
The rule works if the directory doesn't exist on the server, the following works perfectly:
Options -MultiViews -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^newpages/([A-Za-z0-9_\-]+)/(index.html)?$ /newscript/script.php?name=$1 [L,QSA]
And http://mydomain.com/newpages/projekt3/index.html gets the right page.
What am I doing wrong?
Any help would be greatly appreciated.
If a .htaccess in /oldpages has RewriteEngine On, that overrides all rules in the .htaccess in /.

Categories