virtualhost homepage is working, but links are not - macos

I have a site made in Drupal, I finally was forced to set up virtual hosts for XAMPP, given that I am managing multiple local versions. I followed the seemingly straightforward help guides for OSX, however, ONLY the fornt page works, WITH populated data. ANY RESTFUL link however gets a 404.
/Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf:
<VirtualHost p1>
ServerName p1
DocumentRoot /Users/path/to/p1
</VirtualHost>
<VirtualHost p2>
ServerAdmin email#p2.org
ServerName p2
DocumentRoot /Users/path/to/p2
RewriteEngine On
RewriteOptions inherit
</VirtualHost>
httpd.conf in both /Applications/XAMPP/xampp/etc and /etc/apache2 are uncommented:
# Virtual hosts
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
hosts file in /etc/ :
127.0.0.1 p1
127.0.0.1 p2
within the /Users/path/to/p2 the .htaccess file is:
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$">
Order allow,deny
</FilesMatch>
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
# Follow symbolic links in this directory.
Options +FollowSymLinks
# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php index.html index.htm
# Override PHP settings that cannot be changed at runtime. See
# sites/default/default.settings.php and drupal_environment_initialize() in
# includes/bootstrap.inc for settings that can be changed at runtime.
# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
php_flag magic_quotes_gpc off
php_flag magic_quotes_sybase off
php_flag register_globals off
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_flag mbstring.encoding_translation off
</IfModule>
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On
# Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600
<FilesMatch \.php$>
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior. This may
# fail if an error occurs early in the bootstrap process, and it may cause
# problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off
</FilesMatch>
</IfModule>
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
# Block access to "hidden" directories whose names begin with a period. This
# includes directories used by version control systems such as Subversion or
# Git to store control files. Files whose names begin with a period, as well
# as the control files used by CVS, are protected by the FilesMatch directive
# above.
#
# NOTE: This only works when mod_rewrite is loaded. Without mod_rewrite, it is
# not possible to block access to entire directories from .htaccess, because
# <DirectoryMatch> is not allowed here.
#
# If you do not have mod_rewrite installed, you should remove these
# directories from your webroot or otherwise protect them from being
# downloaded.
RewriteRule "(^|/)\." - [F]
# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
# RewriteBase /drupal
#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
# RewriteBase /
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
# Rules to correctly serve gzip compressed CSS and JS files.
# Requires both mod_rewrite and mod_headers to be enabled.
<IfModule mod_headers.c>
# Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
<FilesMatch "(\.js\.gz|\.css\.gz)$">
# Serve correct encoding type.
Header set Content-Encoding gzip
# Force proxies to cache gzipped & non-gzipped css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
</IfModule>
These are the same settings I originally uploaded to the server and the same ones on the server currently. I even pulled them off the server again to make sure they are duplicates.
What am I missing? I can not access the urls directly either. Somehow the routing isn't getting done properly is my best guess.
Upon accessing the homepage, the access_log is:
127.0.0.1 - - [14/Dec/2012:04:53:25 -0500] "GET / HTTP/1.1" 200 13838
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /modules/system/system.base.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /modules/system/system.menus.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /modules/comment/comment.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /sites/all/modules/date/date_api/date.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /modules/system/system.messages.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /modules/system/system.theme.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /sites/all/modules/date/date_popup/themes/datepicker.1.7.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /sites/all/modules/date/date_repeat_field/date_repeat_field.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /modules/node/node.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /modules/field/theme/field.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /modules/search/search.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /modules/user/user.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /sites/all/modules/views/css/views.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /sites/all/modules/ctools/css/ctools.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /themes/bartik/css/layout.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /themes/bartik/css/style.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /themes/bartik/css/colors.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /themes/bartik/css/print.css?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /misc/jquery.once.js?v=1.2 HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /misc/jquery.js?v=1.4.4 HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /misc/drupal.js?menhjd HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /themes/bartik/logo.png HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /themes/bartik/images/buttons.png HTTP/1.1" 304 -
127.0.0.1 - - [14/Dec/2012:04:53:26 -0500] "GET /misc/feed.png HTTP/1.1" 304 -
and then clicking on a link:
the error_log is:
[Fri Dec 14 04:55:45 2012] [error] [client 127.0.0.1] File does not exist: /Users/path/to/p1/projects, referer: http://p1
WHY IS THE SERVER LOOKING FOR A FOLDER, when it should be looking to the database based on the RESTFUL URL?
and the access_log is:
127.0.0.1 - - [14/Dec/2012:04:55:45 -0500] "GET /projects HTTP/1.1" 404 1204
also, the .ht.sqlite permissions are user (read and write), staff (read only) and everyone (read and write
EVEN if the db file wasn't accessible, that would then also preclude the homepage from displaying the current data in the file.....

The httpd-vhosts.conf needs to be updated to include the directory as well.
According to this site:
Lock the site down
You can lock your development site down and prevent outsiders from accessing it on your server by adding the right configurations. Something like the following will prevent outside access to this virtual host:
<VirtualHost *:80>
ServerName p2
DocumentRoot "/Users/path/to/site"
<Directory "/Users/path/to/site">
Options Includes FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
OR 2. Allow outside access
Of course, you may want to be able to access the site from somewhere other than your development machine so you could use something like:
<VirtualHost *:80>
ServerName p2
DocumentRoot "/Users/path/to/site"
<Directory "/Users/path/to/site">
Options Includes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Edit the Httpd-vhosts.conf file in xampp > apache > conf > extra
Restart apache.
Go to your website/wp-admin and log in. Go to settings > permalinks, and click save on your permalinks. If you have your .htaccess file in version control, you will notice it will have edited some values.
This will allow you to fix your issue like it did for me

Related

Images don't load in apache 2.4.7

I just updated my ubuntu to 14.04 and my apache to 2.4.7.
Now when I access any of my webpages on my server, images load for a second, then appear broken.
.htaccess:
RewriteEngine On
# Serve the favicon file from img folder
RewriteCond %{REQUEST_URI} ^/favicon.ico$
RewriteRule ^(.*)$ /img/$1 [NC,L]
# Redirect HTTP traffic to WWW subdomain
RewriteCond %{HTTPS} off [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect HTTPS traffic to WWW subdomain
RewriteCond %{HTTPS} on [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
# Auto Versioning rules
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)\.[\d]+\.(css|js)$ $1.$2 [L]
# Default Zend rewrite rules
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
VHost:
ServerAdmin admin#localhost
ServerName localhost
DocumentRoot /home/mihai/ARTD/www/public/website
<Directory /home/mihai/ARTD/www/public/website >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
<IfModule mod_php5.c>
php_value memory_limit 128M
php_value upload_max_filesize 20M
php_value post_max_size 20M
</IfModule>
ErrorLog /var/log/apache2/ARTD-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/ARTD-access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin#localhost
ServerName localhost
DocumentRoot /home/mihai/ARTD/www/public/website
# Omit this in production environment
SetEnv APPLICATION_ENV local
<Directory /home/mihai/ARTD/www/public/website >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
<IfModule mod_php5.c>
php_value memory_limit 128M
php_value upload_max_filesize 20M
php_value post_max_size 20M
</IfModule>
ErrorLog /var/log/apache2/ARTD-ssl-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/ARTD.log combined
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
#SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt
# Certificate Authority (CA):
# Set the CA certificate verification path where to find CA
# certificates for client authentication or alternatively one
# huge file containing all of them (file must be PEM encoded)
# Note: Inside SSLCACertificatePath you need hash symlinks
# to point to the certificate files. Use the provided
# Makefile to update the hash symlinks after changes.
#SSLCACertificatePath /etc/ssl/certs/
#SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt
# Certificate Revocation Lists (CRL):
# Set the CA revocation path where to find CA CRLs for client
# authentication or alternatively one huge file containing all
# of them (file must be PEM encoded)
# Note: Inside SSLCARevocationPath you need hash symlinks
# to point to the certificate files. Use the provided
# Makefile to update the hash symlinks after changes.
#SSLCARevocationPath /etc/apache2/ssl.crl/
#SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl
# Client Authentication (Type):
# Client certificate verification type and depth. Types are
# none, optional, require and optional_no_ca. Depth is a
# number which specifies how deeply to verify the certificate
# issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth 10
# Access Control:
# With SSLRequire you can do per-directory access control based
# on arbitrary complex boolean expressions containing server
# variable checks and other lookup directives. The syntax is a
# mixture between C and Perl. See the mod_ssl documentation
# for more details.
#<Location />
#SSLRequire ( %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
# and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
# and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
# and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
# and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20 ) \
# or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
#</Location>
# SSL Engine Options:
# Set various options for the SSL engine.
# o FakeBasicAuth:
# Translate the client X.509 into a Basic Authorisation. This means that
# the standard Auth/DBMAuth methods can be used for access control. The
# user name is the `one line' version of the client's X.509 certificate.
# Note that no password is obtained from the user. Every entry in the user
# file needs this password: `xxj31ZMTZzkVA'.
# o ExportCertData:
# This exports two additional environment variables: SSL_CLIENT_CERT and
# SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
# server (always existing) and the client (only existing when client
# authentication is used). This can be used to import the certificates
# into CGI scripts.
# o StdEnvVars:
# This exports the standard SSL/TLS related `SSL_*' environment variables.
# Per default this exportation is switched off for performance reasons,
# because the extraction step is an expensive operation and is usually
# useless for serving static content. So one usually enables the
# exportation for CGI and SSI requests only.
# o StrictRequire:
# This denies access when "SSLRequireSSL" or "SSLRequire" applied even
# under a "Satisfy any" situation, i.e. when it applies access is denied
# and no other module can change it.
# o OptRenegotiate:
# This enables optimized SSL connection renegotiation handling when SSL
# directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
#<FilesMatch "\.(cgi|shtml|phtml|php)$">
# SSLOptions +StdEnvVars
#</FilesMatch>
# SSL Protocol Adjustments:
# The safe and default but still SSL/TLS standard compliant shutdown
# approach is that mod_ssl sends the close notify alert but doesn't wait for
# the close notify alert from client. When you need a different shutdown
# approach you can use one of the following variables:
# o ssl-unclean-shutdown:
# This forces an unclean shutdown when the connection is closed, i.e. no
# SSL close notify alert is send or allowed to received. This violates
# the SSL/TLS standard but is needed for some brain-dead browsers. Use
# this when you receive I/O errors because of the standard approach where
# mod_ssl sends the close notify alert.
# o ssl-accurate-shutdown:
# This forces an accurate shutdown when the connection is closed, i.e. a
# SSL close notify alert is send and mod_ssl waits for the close notify
# alert of the client. This is 100% SSL/TLS standard compliant, but in
# practice often causes hanging connections with brain-dead browsers. Use
# this only for browsers where you know that their SSL implementation
# works correctly.
# Notice: Most problems of broken clients are also related to the HTTP
# keep-alive facility, so you usually additionally want to disable
# keep-alive for those clients, too. Use variable "nokeepalive" for this.
# Similarly, one has to force some clients to use HTTP/1.0 to workaround
# their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
# "force-response-1.0" for this.
#BrowserMatch ".*MSIE.*" \
# nokeepalive ssl-unclean-shutdown \
# downgrade-1.0 force-response-1.0
</VirtualHost>
</IfModule>
Also the browser console lists the following errors multiple times:
Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING
Failed to load resource: net::ERR_EMPTY_RESPONSE
Any idea what I should do?
EDIT:
I forgot to mention that the behaviour is only present on Chrome browser. Firefox renders it properly and there are no errors in Firebug.
change the permision of this file ..
comand is ==>
sudo chmod -R a+rw /var
and then = <img src="../img/y.png">

Apache Access Log Ping

An unrelated issue brought me to looking at my Apache 2 access log one morning and much to my chagrin I noticed a 5 second ping with my local host address. Awesome. Did I have something running locally to hit my Apache HTTP server or was some joker being a d-ck?
127.0.0.1 - - [19/Jun/2014:12:13:58 -0400] "POST / HTTP/1.1" 200 77881
127.0.0.1 - - [19/Jun/2014:12:14:03 -0400] "POST / HTTP/1.1" 200 77881
127.0.0.1 - - [19/Jun/2014:12:14:08 -0400] "POST / HTTP/1.1" 200 77881
127.0.0.1 - - [19/Jun/2014:12:14:13 -0400] "POST / HTTP/1.1" 200 77880
Dropping my network connection stopped the access log entries so it looks like there is some bot pinging with no ident or user name.
Anyone have a tool to diagnose what's coming in?
Looks like Amazon Cloud is the culprit. Not sure why they need to ping my Apache server, but will research this even further with them.
Changed my Apache Log format to combined:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
#LogFormat "%h %l %u %t \"%r\" %>s %b" common
#CustomLog "/private/var/log/apache2/access_log" common
CustomLog "/private/var/log/apache2/access_log" combined
To get better output:
127.0.0.1 - - [19/Jun/2014:12:15:06 -0400] "POST / HTTP/1.1" 200 77881 "-" "Amazon%20Cloud%20Drive/20131119 CFNetwork/673.4 Darwin/13.2.0 (x86_64) (MacBookAir4%2C2)"
127.0.0.1 - - [19/Jun/2014:12:15:36 -0400] "POST / HTTP/1.1" 200 77881 "-" "Amazon%20Cloud%20Drive/20131119 CFNetwork/673.4 Darwin/13.2.0 (x86_64) (MacBookAir4%2C2)"
Recycled the Amazon Cloud Drive service and that looks like whatever process that was hanging around pinging the server dropped off. Curious this did not happen on the countless times I rebooted the machine in the last few days...

mod_rewrite not appending queries

I have a site where I am trying to rewrite search/ks3/7/example-topic to search.php?ks=ks3&year=7&topic=example-topic
I am using apache mod_rewrite and my .htaccess looks like this:
RewriteEngine On
RewriteBase /
RewriteRule ^search/(a-zA-Z0-9+)/(a-zA-Z0-9+)/(a-zA-Z0-9-+) search.php?ks=$1&year=$2&topic=$3 [R=301,L]
However, when I browse to search/ks3/7/example my php $_GET['ks'], $_GET['topic'] and $_GET['year'] contain no data.
My apache error log shows errors in the PHP "undefined index ks" etc.
My rewrite log (which is set to a verbosity of 9) shows:
192.168.0.171 - - [08/Jan/2012:13:11:46 +0000] [192.168.0.10/sid#7ff3cc9b7460][rid#7ff3c65f90a0/initial] (3) [perdir /data/shared/chemistry/] add path info postfix: /data/shared/chemistry/search.php -> /data/shared/chemistry/search.php/ks3/7/example-topic
192.168.0.171 - - [08/Jan/2012:13:11:46 +0000] [192.168.0.10/sid#7ff3cc9b7460][rid#7ff3c65f90a0/initial] (3) [perdir /data/shared/chemistry/] strip per-dir prefix: /data/shared/chemistry/search.php/ks3/7/example-topic -> search.php/ks3/7/example-topic
192.168.0.171 - - [08/Jan/2012:13:11:46 +0000] [192.168.0.10/sid#7ff3cc9b7460][rid#7ff3c65f90a0/initial] (3) [perdir /data/shared/chemistry/] applying pattern '^search/(a-zA-Z0-9+)/(a-zA-Z0-9+)/(a-zA-Z0-9-+)$' to uri 'search.php/ks3/7/example-topic'
192.168.0.171 - - [08/Jan/2012:13:11:46 +0000] [192.168.0.10/sid#7ff3cc9b7460][rid#7ff3c65f90a0/initial] (1) [perdir /data/shared/chemistry/] pass through /data/shared/chemistry/search.php
192.168.0.171 - - [08/Jan/2012:13:11:46 +0000] [192.168.0.10/sid#7ff3cc9b7460][rid#7ff3c65f00a0/subreq] (1) [perdir /data/shared/chemistry/] pass through /data/shared/chemistry/ks3
and my apache virtual hosts file looks like this
<VirtualHost *:80>
ServerAdmin powerj96#hotmail.co.uk
DocumentRoot /data/shared/chemistry
<Directory /data/shared/chemistry/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Mod_Rewrite is definitely working. I have tried the rule:
RewriteRule ^google http://www.google.com [R=301,L]
and this works.
I also run 4 other virtual hosts on the server, 3 of which are just websites and 1 is transmission's web interface.
I am running Ubuntu Server 11.11
EDIT:
I think the problem may be to do with running reverse proxy alongside this. for example, if reverse proxy is changing 192.168.0.10:81 (address of my server and port 81 vhost) to transmission/web then the fact that transmission is running at 192.168.0.10/transmission/web, which is both a vhost and a subdirectory of the site which is running at 192.168.0.10/ (the one in question on this post), may be causing conflicts in the rewrite module. Do you have any ideas of a solution to this if you think it may be the problem.
EDIT:
This is the complete log for everything that happens when I click the link search/ks3/7/example-topic
(1) [perdir /data/shared/chemistry/] pass through /data/shared/chemistry/search.php
(3) [perdir /data/shared/chemistry/] add path info postfix: /data/shared/chemistry/search.php -> /data/shared/chemistry/search.php/ks3/7/example-topic
(3) [perdir /data/shared/chemistry/] strip per-dir prefix: /data/shared/chemistry/search.php/ks3/7/example-topic -> search.php/ks3/7/example-topic
(3) [perdir /data/shared/chemistry/] applying pattern '^search/([^/]+)/([^/]+)/([^/]+)' to uri 'search.php/ks3/7/example-topic'
(1) [perdir /data/shared/chemistry/] pass through /data/shared/chemistry/search.php
(1) [perdir /data/shared/chemistry/] pass through /data/shared/chemistry/ks3
EDIT:
I have realised the source of the problem after looking at that log file. For some reason apache is rewriting search/ks3/7/example-topic to search.php/ks3/7/example-topic before it applies my rewrite, therefore search/ks3/7/example-topic doesn't satisfy the
^search/([^/]+)/([^/]+)/([^/]+)
rule. I have changed the rule to
^search.php/([^/]+)/([^/]+)/([^/]+)
and this works.
Do you have any idea of how to stop apache rewriting search/ks3/7/example-topic to search.php/ks3/7/example-topic ?
It is working now, after removing the QSA, NC and R=301 options.
Your rewritelog doesn't tell much. Remove IP information at the beginning (who cares?). And add the beginning of rewrite (= tell us what is the uri that will be rewritten): take a look at the first line of the following log.
Here's an example of what should be more helpful:
(2) init rewrite engine with requested uri /robots.txt
(3) applying pattern '(.*)setup.php' to uri '/robots.txt'
(3) applying pattern '(.*)admin(.*)' to uri '/robots.txt'
(3) applying pattern '(.*)' to uri '/robots.txt'
(4) RewriteCond: input='www.papdevis.com' pattern='!(papdevis)' [NC] => not-matched
(3) applying pattern '(.*)' to uri '/robots.txt'
(4) RewriteCond: input='www.papdevis.com' pattern='(.*)\.(com|net|org|eu)' [NC] => matched
(2) rewrite '/robots.txt' -> 'http://www.papdevis.fr/robots.txt'
(2) explicitly forcing redirect with http://www.papdevis.fr/robots.txt
(1) escaping http://www.papdevis.fr/robots.txt for redirect
(1) redirect to http://www.papdevis.fr/robots.txt [REDIRECT/301]
(2) init rewrite engine with requested uri /
(3) applying pattern '(.*)setup.php' to uri '/'
(3) applying pattern '(.*)admin(.*)' to uri '/'
(3) applying pattern '(.*)' to uri '/'
(4) RewriteCond: input='www.papdevis.com' pattern='!(papdevis)' [NC] => not-matched
(3) applying pattern '(.*)' to uri '/'
(4) RewriteCond: input='www.papdevis.com' pattern='(.*)\.(com|net|org|eu)' [NC] => matched
(2) rewrite '/' -> 'http://www.papdevis.fr/'
(2) explicitly forcing redirect with http://www.papdevis.fr/
(1) escaping http://www.papdevis.fr/ for redirect
(1) redirect to http://www.papdevis.fr/ [REDIRECT/301]
Rewrite from:
search/ks3/7/example-topic
to
search.php?ks=ks3&year=7&topic=example-topic
And your .htaccess file looks like this:
RewriteEngine On
RewriteBase /
RewriteRule ^search/(a-zA-Z0-9+)/(a-zA-Z0-9+)/(a-zA-Z0-9-+) \
search.php?ks=$1&year=$2&topic=$3 [R=301,L]
It will never work... try this:
RewriteEngine On
RewriteBase /
RewriteRule ^search/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9-]+) \
search.php?ks=$1&year=$2&topic=$3 [QSA,NC,R=301,L]
... or maybe how about taking everything but the slash? This may look like that:
RewriteEngine On
RewriteBase /
RewriteRule ^search/([^/]+)/([^/]+)/([^/]+) \
search.php?ks=$1&year=$2&topic=$3 [QSA,NC,R=301,L]
Please tell me if this works.
Two hints:
If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the .htaccess files), try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

Getting mod_write rules in the Server Config context to apply to all sites

Long time reader, first time poster.
I've got some rewrite rules that work fine within a virtualhost context, but I can't get it to apply at the server config context, which I want to do so it applies to ALL virtual hosts.
The directives:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/?cgi-sys/defaultwebpage\.cgi$ / [R=301,L]
</IfModule>
I've tried altering it to not enforce the start and end as such:
RewriteRule cgi-sys/defaultwebpage\.cgi / [R=301,L]
But I can't trigger it.
What am I missing?
Apache/2.2.13
As asked in the comments, the user is entering:
http://www.example.com/cgi-sys/defaultwebpage.cgi
The following log entry results:
203.4.5.6 - - [05/Apr/2011:10:23:16 +1000] "GET /cgi-sys/defaultwebpage.cgi HTTP/1.1" 200 26 "-"
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko)
Version/5.0.4 Safari/533.20.27"
Now, the site in question has an .htaccess file with this rule that I believe is intercepting this request:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
I temporarily disabled that directive, and then apache just served a vanilla 404:
203.45.73.63 - - [05/Apr/2011:10:27:28 +1000] "GET /cgi-sys/defaultwebpage.cgi HTTP/1.1" 404 - "-"
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko)
Version/5.0.4 Safari/533.20.27"
For what I understand of your rules:
client writes example.com/cgi-sys/defaultwebpage.cgi the rule match and redirect on / that will direct to index.php by rewritting of the last rule.
Does the file example.com/index.php exists?
Of course, you've reloaded the server config files after doing this? You don't have to in per-directory rules but you do here.

Symfony 1.4 routing issues only when using index.php and mod_rewrite

The most succinct way of summarizing the problem at hand:
Development is over, and everything was run against frontend_dev.php during development and testing
This means that all URLs were: server.com/frontend_dev.php/module/action/parm
Moving to production means switching environments, and thusly using index.php instead
server.com/index.php/module/action/parm
Part of moving to production is using mod_rewrite under Apache2 to make the “index.php” part of the URL vanish, but still be functioning
server.com/module/action/parm is still routed against index.php
The URLs are indeed appearing w/o the index.php part, but symfony routing is now complaining:
ie, server.com/goals which routes to goals/index
-- perfectly fine using frontend_dev.php or index.php as an explicit controller
server.com/index.php/goals
-- using no explicit controller (via rewrite):
[Tue Dec 14 12:59:51 2010] [error] [client 75.16.181.113] Empty module and/or action after parsing the URL "/goals/" (/)
I have verified the rewrite is indeed routing to index.php by changing the rewrite to something that doesn’t exist:
[Tue Dec 14 13:05:43 2010] [error] [client 75.16.181.113] script '/opt/www/projects/adam/web/index2.php' not found or unable to stat
I have tried rerouting to frontend_dev.php, but only am provided with more debug information from symfony, none of which is helpful:
404 | Not Found | sfError404Exception Empty module and/or action after parsing the URL "/goals/" (/).
stack trace
1. at () in SF_SYMFONY_LIB_DIR/controller/sfFrontWebController.class.php line 44 ...
2. at sfFrontWebController->dispatch() in SF_SYMFONY_LIB_DIR/util/sfContext.class.php line 170 ...
3. at sfContext->dispatch() in SF_ROOT_DIR/web/frontend_dev.php line 13 ...
I have tried the using the RewriteBase option in .htaccess, but that does not help any, nor changing the true/false in the configuration line of the controllers
I hope this provides enough to understand why we’re confused, and able to direct us to a resolution.
Following is the current .htaccess and index/frontend configuration lines
Index.php:
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
Frontend_dev.php:
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
.htaccess:
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} ..+$
#RewriteCond %{REQUEST_URI} !.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
I had similar issue and setting 'AllowOverride' to ALL for Symfony's WEB folder in Virtual Host's config sorted out this problem.
Welcome to Stack Overflow.
Maybe you're confusing the "index" route with "index.php"?
These URLs should theoretically all work.
server.com/frontend_dev.php/goals/index
server.com/index.php/goals/index
server.com/goals/index
server.com/goals
I can't remember if the trailing slash, like server.com/goals/, works or not. There's a gotcha there.

Resources