1

I have a PHP web application on a Apache Web Server.

The path to to web application on the Server is: /var/www/html/intern/organisation/example_app

The URL to the web application is:
https://www.example.de/org1/intern/example_app/

I want, that all request, e.g. https://www.example.de/org1/intern/example_app/view1/ are redirected to

https://www.example.de/org1/intern/example_app/index.php 

On my local XAMPP Server I use following .htaccess file, that works for that purpose:

RewriteEngine On RewriteBase /example_app RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ index.php [L] 

But I have no idea, how that file should look like on the Server? I also use a httpd.conf on the server. I wondering, if that file interferes with the .htaccess file, that lies below: /var/www/html/intern/organisation/example_app/

Has anyone an idea how to config the rewriting on the Server?

1
  • Where are these .htaccess file(s) located? Do you have multiple .htaccess files (in other directories)? The file-path and URL-path on the server don't appear to match? Do you have additional rewriting (or Alias) configured in the server config, or is example_app in the file-path a different directory to example_app in the URL-path? Commented Jan 15, 2024 at 12:59

2 Answers 2

0

The .htaccess file in the /org1/intern/example_app/ subdirectory should look like this:

DirectoryIndex index.php RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] 

You can then use the same .htaccess file locally and on the live server, providing it goes in the example_app/ subdirectory.

Providing the .htaccess file is located in the same directory as the index.php file you are wanting to rewrite to then you don't need the RewriteBase directive.

The DirectoryIndex directive is likely already set to index.php in the server config, so it may not be required here, but for completeness it should be included. It is required for when the application directory itself is requested (ie. https://www.example.de/org1/intern/example_app/).

Note that this is an "internal redirect", or more commonly referred to as a "rewrite". If you simply say "redirect" then that implies an "external (HTTP) redirect", which is something else entirely.


I wondering, if that file interferes with the .htaccess file, that lies below: /var/www/html/intern/organisation/example_app/

Multiple .htaccess files (and the server config) can conflict. However, mod_rewrite directives in a child config (in the same context, ie. directory) will completely override mod_rewrite directives in the parent config (by default).


Aside: (or possibly not)

The path to to web application on the Server is: /var/www/html/intern/organisation/example_app

The URL to the web application is: https://www.example.de/org1/intern/example_app/

Although, slightly confusing, the file-path and URL-path don't appear to match? Do you have additional rewriting or Alias configured in the server config, or is example_app in the file-path a different directory to example_app in the URL-path?

0

Many thanks for the detailed answers. The Rewriting Rules were not the problem.

The problem was simple. The whole .htaccess didn't word because I had to activate AllowOveride on the httpd.conf.

2
  • the URL ist different from the file-path. Because there is a CMS on another server for our whole organisation. My apps on my Server are Part of that CMS. I don't know how that technically works, because someone else is responsible for the CMS. Commented Jan 15, 2024 at 13:14
  • "The Rewriting Rules were not the problem." - although the rewrite rules you posted in the question would not have worked on the "server" due to the incorrect RewriteBase directive, as mentioned in my answer. Commented Jan 15, 2024 at 15:42

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.