I am working on a small project on my local machine (in a nginx docker container) and I today was the first time when I uploaded it to my webserver and found out that it’s an apache server.
Everything works fine, except for my router.php.
When I visit example.com/admin I get an error 404 on my apache server but in my nginx docker container I am getting the correct page though.
I am getting AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
in my error_log_apache
<?php //Router.php namespace blog; class Router public function __construct(private AdminPage $adminPage, private AdminContentPage $adminContentPage, private ArticlePage $articlePage, private VariablesWrapper $variablesWrapper, private SessionManager $sessionManager){} public function getPageForUrl() : Page { switch ((string)$this->variablesWrapper->getRequestUri()){ case '/admin': if ($this->sessionManager->isAuthenticated()){ return $this->adminContentPage; } else { return $this->adminPage; } case preg_match('//([A-Za-z]w+)/?article=[0-9]{1,5}/',(string)$this->variablesWrapper->getRequestUri()): //Hello_world/?article=0 default: return $this->articlePage; } } }
Since it probably has something to do with the configs, and I have to idea what exactly, I’ll give you my default.conf which is the config for my nginx server.
server { listen 80; index index.php index.twig; server_name localhost; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; root /var/www/html/public; location / { try_files $uri /index.php$is_args$args; } location ~ .php$ { try_files $uri = 404; fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_pass php:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } }
and here is my untouched httpd.conf from my apache server Edit: Apparently I have to rights to change the httpd config
# managed by uberspace-generate-httpd-config <Directory /var/www/virtual/USERNAME> AllowOverride AuthConfig FileInfo Indexes Limit Options=ExecCGI,Includes,Indexes,MultiViews,SymLinksIfOwnerMatch Options +Includes </Directory> <VirtualHost *> ServerName USERNAME.uber.space ServerAlias blog.returnnull.de ServerAlias www.returnnull.de ServerAlias USERNAME.uber.space ServerAlias returnnull.de SuexecUserGroup USERNAME USERNAME DocumentRoot /var/www/virtual/USERNAME/html ServerAdmin USERNAME@uber.space AllowEncodedSlashes NoDecode ErrorLog /readonly/USERNAME/logs/error_log_apache LogLevel notice RewriteEngine On # If there is a host-specific pseudo-DocumentRoot, use it instead of the default one RewriteCond /var/www/virtual/USERNAME/%{HTTP_HOST} -d RewriteRule (.*) /var/www/virtual/USERNAME/%{HTTP_HOST}$1 <FilesMatch ".php$"> SetHandler "proxy:unix:/run/php-fpm-USERNAME.sock|fcgi://php-fpm-USERNAME" </FilesMatch> <Proxy "fcgi://php-fpm-USERNAME" max=10> </Proxy> </VirtualHost>
Advertisement
Answer
You have to add a .htaccess
file on the root of your project.
RewriteBase / Options -Indexes RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L]
For this you need to enable rewrite module for apache you can do this for by running sudo a2enmod rewrite
after this you need to restart apache server sudo service apache2 restart