Skip to main content
added 79 characters in body
Source Link
Maciek
  • 139
  • 1
  • 7

I am trying map all wildcards for a directory /a/* onto on file article.php using AliasMatch ^/a/(.*) /article.php but without redirecting (I want to keep the url looking the same). But I am getting a The requested URL was not found on this server. error.

Is AliasMatch even the right way to do this? Or is there a better way.

I am trying to achieve something like:

example.com/a/hello example.com/a/this-is-an-article 

article.php

echo basename($_SERVER['REQUEST_URI']; 

result:

hello this-is-an-article 

000-default.conf

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] RewriteRule ^ https://%1%{REQUEST_URI} [END,L,R=permanent] AliasMatch ^/a/(.*) /article.php </VirtualHost> <Directory /var/www> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> 

I am trying map all wildcards for a directory /a/* onto on file article.php using AliasMatch ^/a/(.*) /article.php but without redirecting (I want to keep the url looking the same). But I am getting a The requested URL was not found on this server. error.

I am trying to achieve something like:

example.com/a/hello example.com/a/this-is-an-article 

article.php

echo basename($_SERVER['REQUEST_URI']; 

result:

hello this-is-an-article 

000-default.conf

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] RewriteRule ^ https://%1%{REQUEST_URI} [END,L,R=permanent] AliasMatch ^/a/(.*) /article.php </VirtualHost> <Directory /var/www> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> 

I am trying map all wildcards for a directory /a/* onto on file article.php using AliasMatch ^/a/(.*) /article.php but without redirecting (I want to keep the url looking the same). But I am getting a The requested URL was not found on this server. error.

Is AliasMatch even the right way to do this? Or is there a better way.

I am trying to achieve something like:

example.com/a/hello example.com/a/this-is-an-article 

article.php

echo basename($_SERVER['REQUEST_URI']; 

result:

hello this-is-an-article 

000-default.conf

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] RewriteRule ^ https://%1%{REQUEST_URI} [END,L,R=permanent] AliasMatch ^/a/(.*) /article.php </VirtualHost> <Directory /var/www> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> 
Source Link
Maciek
  • 139
  • 1
  • 7

Apache AliasMatch with Wildcard Not Working As Intended

I am trying map all wildcards for a directory /a/* onto on file article.php using AliasMatch ^/a/(.*) /article.php but without redirecting (I want to keep the url looking the same). But I am getting a The requested URL was not found on this server. error.

I am trying to achieve something like:

example.com/a/hello example.com/a/this-is-an-article 

article.php

echo basename($_SERVER['REQUEST_URI']; 

result:

hello this-is-an-article 

000-default.conf

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] RewriteRule ^ https://%1%{REQUEST_URI} [END,L,R=permanent] AliasMatch ^/a/(.*) /article.php </VirtualHost> <Directory /var/www> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>