XAMPP URL with 'error' end to 404 Not found - .htaccess

Is there some problem with URLs which have word error in them? Because if I enter route like http://eshop.local/controller/action, where controller can be anything at all, there's no problem, but if controller is error, it returns:
Error 404 Page not found
My htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
http://eshop.local/error works fine but if is followed by some action whatever word, number, or anything returns 404 error.
EDIT:
Just now i have copied it to my webhosting, everything with error urls is working fine, so problem is on XAMPP side.

Hold Your Breath
Open xampp control panel
Stop Apache
Click the Config button on the Apache row, and select httpd.conf
In that file, search for <Directory "C:/xampp/htdocs">
A bit lower, you may see a line like this: # AllowOverride All. Remove the #, which is a comment
Save the file
Restart Apache, say a prayer, cross your fingers and hold your breath

Response from Altrea, Moderator from XAMPP forum:
All URLs that are used in an Alias, Location or Proxy definition.
There are a bunch of them in XAMPP Apache (depending on which config files are activated or not some of them are maybe not used):
/cgi-bin/
/error/
/examples
/icons/
/licenses
/manual
/my-gateway/
/phpmyadmin
/php-cgi/
/security
/server-info
/server-status
/uploads
/webalizer
/webdav
In your case /error/ is already useds
Is it possible to reuse for example that /error/ or it' s better to change it in my code for example to /err/ ?
This Alias is used for the default Apache
error Pages (everywhere ErrorDocuemnt is used this Alias is used).
So it is possible to change it in XAMPP, but you have to
search and replace multiple files.

Related

Doing URL Rewriting and Redirections (.htaccess) with same code working both on WAMP localhost and remote folder?

first of all, I'm sorry for this umpteenth topic about this kind of problem.
I've tried to adapt other topics to my problem for months without being able to figure out how to do. That's why I'm writing today, it's really bugging me and as of today, I can only successfully do URL rewriting on remote but always coding in production remote folder isn't reliable solution.
This is what my file tree look like :
Firstly, I'd like to be redirected from the root of this 'template1' project to the root of the 'public' subfolder ; and secondly, I'd like to rewrite URLs so this kind of URL :
template1/index.php?route=qwertyuiop
turns into that :
template1/qwertyuiop
Both these things I want work but only on my remote folder on Ionos and I had to do weird things. For example for the redirection, I'm directly linking domain to subfolder and for URL rewriting I do :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.zip|\.pdf|\.css|\.svg|\.js)$
RewriteRule ^(.*)$ /index.php?route=$1 [L,QSA]
Anyways, this works fine on remote folders and when I do PHP header("location:/azertyuiop") it works fine but in localhost it tries to search at the root of WAMPserver and I don't know how to proceed to fix it while keeping same code for both local and remote.
If any of you could help me figure out how to deal with this problem, it would be really appreciated as reading topics and putting whatever I can in my .htaccess doesn't work on localhost.
Ok, sooo thanks #MrWhite for basically telling me about VirtualHost. I never saw about it in any topics so I was searching maybe in the wrong direction.
Everything is working fine, now. So in case in the future someone gets through it, I will explain what I did to make it work in localhost. What I will tell is translated from a website I've found in my native language ( How to configure VirtualHost (French) ).
STEP 1 : edit Apache's config in Wamp
In the 'httpd-vhosts.conf' file located in 'C:/wamp64/bin/apache/apache2.4.46/conf/extra/httpd-vhosts.conf' (in my case), I had to add these virtual host lines :
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.localhost
DocumentRoot "${INSTALL_DIR}/www/projets/projets_persos/tests/template1/public"
ServerName template1.local
ServerAlias template1.local
ErrorLog "logs/template1.local-error.log"
CustomLog "logs/template1.local-access.log" common
</VirtualHost>
Then I had to modify Apache's main config file called 'httpd.conf' located in 'C:/wamp/bin/apache/apache2.4.46/conf/httpd.conf' (in my case) and uncomment the following line :
#Include conf/extra/httpd-vhosts.conf (in my case, it was already uncommented)
After that, the website says to restart Wamp's services before step 2, which I did after step 2 below and it stills work without any trouble. So anyway, I guess it will be same for you, do it now or after step 2.
STEP 2 : edit Windows' hosts file
At bottom of the 'hosts' file located in 'C:/Windows/System32/drivers/etc/hosts' I added the following line at bottom of the file to override the previous rule :
127.0.0.1 template1.local
Aaand, that's all.
=-=-=-=-=
As a proof it's working well, here's a screenshot of my project :
Here you can see on the picture I exploded my route in an array. I do this for personal purposes, to be able to route according to whatever bit of string I want. If you want to get rid of the 'public' value in the route, just type $_GET['route'] = str_replace('public/', '', $_GET['route']); before putting each of its fields in the array. Then, it will look like this :
Also, of course, I used .htaccess to be able to do URL Rewriting, here's my .htaccess file :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.zip|\.pdf|\.css|\.svg|\.js)$
RewriteRule ^(.*)$ /index.php?route=$1 [L,QSA]
It's a bit off topic but in case you'd need to know, the RewriteCond lines allow to type in the true URL of assets that have these extensions and it won't rewrite as they are true URLs.
=-=-=-=-=
Anyway, this is the end of my solution, thanks again for helping me and all's well that ends well. The End.

htaccess works with www.example.com but not example.com

I have installed Ghost, which needs nodejs to run. I'm doing this on an Apache Linux server via managed hosting. They kindly let me login with SSH access so I've been able to setup nodejs and Ghost using the standard installation instructions. I installed ghost to the root of my domain so in normal operation someone would go to example.com and it'll show them my blog. Well that's what I'd hoped.
However now when I've come to load Ghost in my browser I discover because I'm accessing it the way I am, and that Ghost doesn't do server configuration, I seem to need an htaccess file to be able to make the site reachable.
So, I have created this htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ http://127.0.0.1:65515/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:65515/$1 [P,L]
</IfModule>
With that saved to the root, if I go to example.com/ghost (the admin panel for Ghost) it works. Nothing wrong there, looks great. If however I try and visit the root, ie goto example.com, instead of showing me the index, it shows me index.js - that is, it literally loads the contents of Ghost's index.js file and displays it instead of parsing it and displaying the main index of the website.
IF however I go to www.example.com then it all works. So whatever the problem is it's because I'm not using www. in the domain.
I would prefer it to work both with or without the www in the URL though. I did try adding some solutions to redirect non-www requests to www.example.com to th ehtaccess but for some reason it still doesn't work (as in if I type example.com it doesn't redirect me to www.example.com).
I think maybe you should be using mod_proxy rather than mod_rewrite. At least, that's what I've used in the past. Apache will catch requests coming in on port 80 and then redirect them to port 65515 where your node server is listening.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass
Like this:
ProxyPass / http://localhost:65515/
I figured it out. Wasn't anything to do with htaccess, or Ghost or nodejs or anything like it. No, instead the problem was the sodding server was caching the website. I discovered the setting to delete the cache and it all started working fine, so, this is now solved.

htaccess rewrite working offline on WAMP but not online on linux host

I'm just going to explain my problem here :
http://mysite.com/movie/20000
should be rewritten to
http://mysite.com/movie.php?id=20000
my htaccess file :
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^movie/([0-9]+)$ movie.php?id=$1
On my localhost WAMP installation this works fine, but when I put it online on my linux host it doesn't completely work. It does go to the movie.php page, but it seems it gives no GET parameter id.
Edit :
if I use
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^movie([0-9]+)$ movie.php?id=$1
then
http://mysite.com/movie20000
Goes to the correct page, but I would like /movie/20000 and not just /movie20000
It also seems that my host automatically rewrites a visit to mysite.com/movie to mysite.com/movie.php
After searching for a long time, and pulling some of my lovely hair out I found the solution.
I just added
Options -MultiViews
to my htaccess file and that fixed it.
Why? Because .php was being added to urls without an extension, which I really did not need.
This should work.
RewriteRule ^movie/([0-9]+)$ http://mysite.com/movie.php?id=$1 [NC,L]
Don't forget the [NC, L] it means Case insensitive, last rule... If you don't, it will continue to process through your htaccess rules, maybe triggering other ones.
Still, the stuff below is good advice.... :)
Check to see if the Rewrite module is loading with apache. Look for this line in the httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
Check to see if your apache config allows for .htaccess files for your system or in the virtual host definition.
Also, test with a simpler rewrite catch all and test that alone to see if it's working at all like this (get rid of everything else in your htaccess file to limit the test):
RewriteEngine On
RewriteRule ^(.*)$ http://www.google.com [L,R=301]
Any request to your site should go to google if the configuration for apache is correctly set.

.htaccess - How to hide the internal directory used by subdomains?

I installed a small FTP space for my classmates which allows them to upload school related documents to my server. After the files have been uploaded, they can be easily accessed via a subdomain i.e. ftp.mydomain.com
Everything is working fine, the files can be downloaded and everything works properly.
There are two things which still annoy me though:
If you enter ftp.mydomain.com you see Index of /my_internal_directory instead of something like Index of /
Once you enter a sub-directory and click the Parent Directory link it will redirect you to ftp.mydomain.com/my_internal_directory/ as well
Is there any way to hide my_internal_directory ?
This is the content of my .htaccess file so far:
RewriteEngine on
RewriteCond %{HTTP_HOST} ftp\.mydomain\.com
RewriteCond %{REQUEST_URI} !^/my_internal_directory/
RewriteRule ^(.*)$ /my_internal_directory/$1 [L]
Any help would be greatly appreciated.
If you are using linux server then you can remove read permission for folder my_internal_directory
If not resolve, try to add:
Options -Indexes
on top of the file.
If still doesnt resolve please post your .htaccess file... :)

RewriteRule variables blank

I have a couple of rewrite rules in htaccess. They work on one server but not another. My script is as follows (I've commented out how the urls look):
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/images/
#example.com/regions/fife/
RewriteRule ^regions/([A-Za-z0-9\-\+\']+)/?$ /regions.php?region=$1 [L]
#example.com/regions/fife/dunfermline
RewriteRule ^regions/([^/]+)/([^/]+)$ /regions.php?region=$1&town=$2 [L]
It returns two variables (region & town) I can manipulate in PHP, and throw up the appropriate content. I have a Rackspace server, and the script works perfectly, but on another server (Freedom2surf) it only works so far. It doesn't return the variables. I get a blank $_GET array...
Any ideas? F2S aren't giving me any clues, just that I should check my code. But if it works on another server, then what gives? Is it an Apache setting that is different?
I think you may be after the 'QSA' flag, which will append the query string from the original request to the redirected request, e.g:
#example.com/regions/fife/
RewriteRule ^regions/([A-Za-z0-9\-\+\']+)/?$ /regions.php?region=$1 [L,QSA]
This sounds like you have a mod_negotiation conflict here and you need to turn Multiviews off. Sometimes apache default configurations have Multiviews turned on by default. What that does is it will look at a request, say, /regions/1234 and mod_negotiation will notice that there is a file /regions.php and assume that the request is actually for that php file. It'll thus serve /regions.php/1234 and completely bypass mod_rewrite. You can use Options to turn it off. Just add this to the top of your htaccess file:
Options -Multiviews

Resources