There are some PHP files on an external drive which is mapped to the Z: drive on a Windows 10 machine. This code is in the httpd-vhosts.conf Apache file:
<VirtualHost *:8080>
DocumentRoot "Z:/files/xampp/htdocs"
<Directory "Z:/files/xampp/htdocs">
Options Indexes
Require all granted
</Directory>
</VirtualHost>
The task at hand is to allow .htaccess overrides for a file path within the path shown above. In the httpd.conf file the rewrite module is enabled. That line looks like this: LoadModule rewrite_module modules/mod_rewrite.so. I tried adding this code to the httpd.conf file:
<Directory "Z:/files/xampp/htdocs/miscellaneous/WebServiceExamples">
AllowOverride All
</Directory>
The Apache web server was stopped and restarted after making these changes. The code in .htaccess looks like this:
<IfModule mod_rewrite.c>
# turn rewrite engine on
Options +FollowSymlinks
RewriteEngine on
# map neat URL to internal URL
RewriteRule ^mobile/list/$ RestController.php?view=all [nc,qsa]
RewriteRule ^mobile/show/([0-9]+)/$ RestController.php?view=single&id=$1 [nc,qsa]
</IfModule>
However, when a URL that should be handled by the rewrite rule in the .htaccess file is entered in the Chrome address bar the result is an Object not found! Error 404. Where did I go astray?
EDIT:
Another thing I tried was putting httpd.conf back to its original state, then modifying httpd-vhosts.conf as follows:
<VirtualHost *:8080>
DocumentRoot "Z:/files/xampp/htdocs"
<Directory "Z:/files/xampp/htdocs">
Options Indexes
Require all granted
</Directory>
<Directory "Z:/files/xampp/htdocs/miscellaneous/WebServiceExamples">
AllowOverride All
</Directory>
</VirtualHost>
After stopping and restarting the Apache web server, the result is still the same as before:
Object not found! Error 404.
Figured this out. The configuration files were left in the state as described in the Edit section in the original post. The Troubleshooting section in this link was a helpful guide for determining that the configuration files were set up correctly.
This was entered as the URL in Chrome's address bar: http://localhost:8080/miscellaneous/WebServiceExamples/SimpleRestfulWebService/mobile/list. Notice there is no trailing forward slash. The rewrite rule was in .htaccess was written in such a way that made a trailing forward slash mandatory. When the rewrite rule lines were modified to make the trailing slash optional, then it worked fine. Here are the modified rewrite rules:
RewriteRule ^mobile/list/?$ RestController.php?view=all [nc,qsa]
RewriteRule ^mobile/show/([0-9]+)/?$ RestController.php?view=single&id=$1 [nc,qsa]
Related
I got a basic problem that I can't resolve.
I set up a LAMP server on a Debian 10 machine which run into a Docker container.
PHP and the services Apache and MySQL are functionnal, but I got a problem with the URL rewriting.
It don't run, even on the basic entry point of my web server which is : "http://localhost/"
If I use the real adress, It work, but if I brink a "virtual" adress like "http://localhost/toto" for exemple, I got a 404 error from Apache.
Here is the content of my .htaccess file that I put on the root of my base directory "/var/www/html" :
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !/index.php$
RewriteCond %{REQUEST_URI} !(.css|.js|.jpg|.jpeg|.png|.svg|.ttf|.woff|.woff2|.pdf|.zip|.mp4|.avi|.ogg)$
RewriteRule .* /index.php
In the configuration file of my default website (/etc/apache2/sites-available/000-default.conf), I've the directive "DocumentRoot /var/www/html".
If I do a phpinfo(), I see the "mod_rewrite" in the loaded_module.
Is anybody know how can I solve it ?
Mickaƫl
Finally..., It's OK !
My .htacess file was just ignored by Apache, because the AllowOverride statement was set to "None" by default in my "apache2.conf".
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
I changed it by "AllowOverride All", I restarded Apache and I could valid that the rewriting work fine.
I discovered this error on a CodeIgniter project. The htaccess file is rewriting to /index.php/$1 [L]
I am aware that this can be fixed by modifying the rewrite rule in htaccess (.htaccess problem: No input file specified), however I am really looking for a server-wide fix that can be done without modifying each site's htaccess file.
So is there anything that can be added to the vhost (or somewhere else) to make FastCGI see and process the index.php file? My vhost currently looks like this:
<VirtualHost *:80>
ServerAlias dev.project.com
DocumentRoot "c:/dev.wamp/www/project"
<Files ~ "\.php$">
FcgidWrapper "c:/dev.wamp/bin/php/5.3/php-cgi.exe" .php
</Files>
</VirtualHost>
I am unable to get the rewrite working on Dispatcher module of AEM.
Following is what's happening with my configuration:
Dispatcher configuration:
Snippet of my httpd.conf
LoadModule dispatcher_module modules/mod_dispatcher.so
<IfModule disp_apache2.c>
DispatcherConfig conf/dispatcher.any
DispatcherLog logs/dispatcher.log
DispatcherLogLevel 3
DispatcherNoServerHeader 0
DispatcherDeclineRoot 0
DispatcherUseProcessedURL 0
DispatcherPassError 0
</IfModule>
<VirtualHost *:80>
ServerName mobile.example.com.au
DocumentRoot "/var/www/html/content/mobile"
RewriteEngine on
RewriteRule ^/(.*)\.html$ /content/mobile/$1.html [PT]
<Directory "/var/www/html/content/mobile">
<IfModule disp_apache2.c>
SetHandler dispatcher-handler
ModMimeUsePathInfo On
</IfModule>
Options FollowSymLinks
AllowOverride None
# AddType text/html .html
# AddOutputFilter INCLUDES .html
# Options +Includes
</Directory>
</VirtualHost>
......
Now, if I try to access the mobile.example.com.au/home.html, it shows up this 404 and says no content:
Not Found
The requested URL /content/mobile/home.html was
not found on this server.
Though I am able to hit the page directly by using the full path:
http://mobile.example.com.au/content/mobile/home.html and the page is rendered.
What am I missing here? Is it something to do with the Document root?
Also, how do we set the default landing page for mobile.example.com.au to show up home.html.
Can you please check rewrite logs to see how request is flowing?
Also, to set default landing page, you can use following rule
RewriteRule ^/$ /content/mobile/home.html [PT,L]
I believe you need to change this line:
DispatcherUseProcessedURL 0
to
DispatcherUseProcessedURL 1
... so that Dispatcher uses the rewritten URL for filter checks, cache structure, and the request to AEM. You'll also need to add the RewriteRule as Mohit suggested, probably as the first rule - but only if you want / to show the /home.html page.
See also: Adobe documentation on Dispatcher configuration
I have a default Zend Framework application installed under /var/www/html/zend_example. The public directory is: /var/www/html/zend_example/public.
I also have other non-zend sites in /var/www/html. For example, /var/www/html/other_site.
How can I configure the ZF site to work under http://MYDOMAIN/zend_example while simultaneously allowing http://MYDOMAIN/other_site to work?
Here is my apache config file:
<VirtualHost *:80>
DocumentRoot /var/www/html/zend_example/public
SetEnv APPLICATION_ENV "development"
<Directory /var/www/html/zend_example/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Here is the .htaccess file in /var/www/html/zend_example/public:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I just want to get a development ZF site up and running, while also having other sites available (under the same base URL).
Right now, all requests redirect (or rewrite?) to the base URL (http://MYDOMAIN).
Thanks!
Edit #1
I edited the vhost for both zend_example and other_site so that each DocumentRoot is set to /var/www/html, rather than the subdirectories for each site. This made it possible to access both sites in their respective URLs - other_site: http://MYDOMAIN/other_site and zend_example: http://MYDOMAIN/zend_example/public. Now, I believe there is a problem with the .htaccess file that is in the /var/www/html/zend_example/public directory. I cannot access default "Zend" URLs such as http://MYDOMAIN/zend_example/public/index/index which should point to the IndexController. Instead I receive a 404 error.
Edit #2
If I disable all vhosts except for the zend_example one, and the zend_example vhost has DocumentRoot /var/www/html set, then I am able to run the Zend site under http://MYDOMAIN/zend_example/public, including specific default Zend routes, such as http://MYDOMAIN/zend_example/public/index/index. This breaks when I enable another vhost, although I am still able to access the main index page for Zend at http://MYDOMAIN/zend_example/public.
Edit #3
I ended up toying with this for hours. It seems that there is some unique configuration that needs to be done since my server is centos 6.0. I ended up setting up a Debian 6.0 server and was able to get my virtual hosts setup correctly, including the Zend site! I'd still like to come back and solve the issue on centos, though.
you're missing the ServerName option in your vhost. Also you may encounter some difficulties if you don't allow followSymlinks in your directory declaration, try something like:
//the ServerName is the name that would follow http:// (http://zend.example/module/controller/action)
<VirtualHost *:80>
DocumentRoot /var/www/html/zend_example/public
ServerName zend.example
SetEnv APPLICATION_ENV "development"
<Directory /var/www/html/zend_example/public>
DirectoryIndex index.php
Options Indexes FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I'm not a *nix user so I'm not sure if you have change anything that resembles a windows hosts file or not, but it might pay to investigate. (it looks like you will have to edit the hosts file, it should be at /etc/hosts add a line like 127.0.0.1 zend.example where zend.example = ServerName from your vhost)
P.S. you'll probably have to make a vhost (as the first one in the list if all of your vhost are in one file) for localhost if you need localhost available. I know I have to do this on windows.
I am trying to redirect /folder to / using .htaccess but all am I getting is the Apache HTTP Server Test Page.
My root directory looks like this:
/
.htaccess
-/folder
-/folder2
-/folder3
My .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule ^(.*)$ folder/$1 [L]
What am I doing wrong? I checked my httpd.conf (I'm running Centos 5.3) and the mod_rewrite library is being loaded. As a side note, my server is not a www server, its simply a virtual machine so its hostname is centosvm.
Addition: I have found that the mod_rewrite module is loaded, but none of my .htaccess redirects seem to be working.
Addition: My httpd.conf directory directive looks like:
<Directory />
Options FollowSymLinks
#AllowOverride None
</Directory>
What does you AllowOverride say? (see: http://httpd.apache.org/docs/2.0/howto/htaccess.html)
And that would bring us to requiring this in (virtual)host/directory settings:
AllowOverride FileInfo