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

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.

Related

View page not found in Laravel

Today I went from my Windows server to Ubuntu. I transferred my Laravel project that I had on IIS to apache2 and installed mod rewrite. However, I can't see the pages. This is the error I get: View [pages.maintenance] not found.
This is what I added to the 000-default.config configuration file:
<Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</ Directory>
This is my htaccess (found in /var/www/html/public, (my DirectoryRoot):
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </ IfModule>
    RewriteEngine On
    # Handle Authorization Header
    RewriteCond% {HTTP: Authorization}.
    RewriteRule. * - [E = HTTP_AUTHORIZATION:% {HTTP: Authorization}]
    # Redirect Trailing Slashes If Not A Folder ...
    RewriteCond% {REQUEST_FILENAME}! -D
    RewriteCond% {REQUEST_URI} (. +) / $
    RewriteRule ^% 1 [L, R = 301]
    # Handle Front Controller ...
    RewriteCond% {REQUEST_FILENAME}! -D
    RewriteCond% {REQUEST_FILENAME}! -F
    RewriteRule ^ index.php [L]
</ IfModule>
How come I get this? I checked the rewritten mod change and it's okay.

mod_rewrite: app1 to app1/ and app2 to app2/

I'm new to mod_rewrite, but I have successfully set up an Apache 2.4 Reverse Proxy (doesn't use <directory>). However, now I need to redirect two literal paths (app1 and app2 to app1/ and app2/):
https://external.com/app1 to https://internal.com/app1/ (with the slash)
https://external.com/app2 to https://internal.com/app2/ (with the slash)
where app1/ and app2/ are
ProxyPass "/app1/" "https://internal.com/app1/"
ProxyPassReverse "/app1/" "https://internal.com/app1/"
ProxyPass "/app2/" "https://internal.com/app2/"
ProxyPassReverse "/app2/" "https://internal.com/app2/"
I've tried variations on these, but they cause loops or otherwise don't work.
RewriteEngine On
RewriteRule ^/(app1)$ $1/ [PT]
RewriteRule ^/(app2)$ $1/ [PT]
Thoughts? Again, I don't know mod_rewrite well.
I got this working with redirect instead of mod_rewrite:
Redirect /app1 /app1/
Redirect /app2 /app2/

Wordpress localhost doesn't show front-end

Can't see the front end of my wordpress localhost.
The process I've done:
1. I installed wordpress locally with BitNami on Mac OX.
2. imported an existing data base to the phpmyadmin.
3. changed the wp-config file to support the local host database.
4. added these two lines
define('WP_HOME','http://localhost/wordpress');
define('WP_SITEURL','http://localhost/wordpress');
5. logged in to my wp-admin.
Now I can see the site's WP-ADMIN and do things in it BUT I cannot view the front end.
whenever I try i get:
can't establish a connection to the server at 127.0.0.1.
or if i try to view a post i get
"The requested URL /site/2013/02/13/idho_global/ was not found on this server."
If I'm trying to preview a draft I see it the way it should appear.
any help?
Check the database via phpmydmin and change the url if you didn't do it.
In the wp_options check if siteurl & home are set to localhost
Update : you should have a look to the 'Moving Wordpress page' https://codex.wordpress.org/Moving_WordPress
It explains very well ho to change permalinks and things to do after moving a Wordpress.
If your permalinks don't works, check if you have a .htaccess in the root directory. The content should be :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You need to update the database urls. Wordpress hardcodes them. Run the sql below replacing "old-url.com/wordpress" and "new-url.com/wordpress" with your urls
UPDATE wp_posts SET guid = REPLACE(guid, 'old-url.com/wordpress', 'new-url.com/wordpress');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'old-url.com/wordpress', 'new-url.com/wordpress');
UPDATE wp_options SET option_value = REPLACE(option_value, 'old-url.com/wordpress', 'new-url.com/wordpress');

virtualhost homepage is working, but links are not

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

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