I want to configure a mod_rewrite rule without using .htaccess files. When I put rules in .htaccess files they work fine, but I would prefer to leave all of the configuration in my /etc/apache2/sites-available/[site name] config file.
When I place the same RewriteRules within the VirtualHost or Directory directives, nothing works. What am I doing wrong? Here is a sample from my VirtualHost config file:
<Directory />
Options FollowSymLinks
# AllowOverride is on for the .htaccess files to work
AllowOverride All
RewriteEngine On
RewriteRule ^oldsite\.php$ newsite.php
</Directory>
I'm thinking I might be overlooking some directive within the apache2.conf file, but I'm not sure. Help. :)
You’re using a RewriteRule pattern that is meant for an .htaccess file. The reason:
When using the rewrite engine in .htaccess files the per-directory prefix (which always is the same for a specific directory) is automatically removed for the pattern matching and automatically added after the substitution has been done.
So try this rule with the full URL path:
RewriteRule ^/oldsite\.php$ /newsite.php
Related
What is the code used in .htaccess to prevent access of other files in my public folder ( LARAVEL project under shared hosting )?
I have a file called index.php and I want this file to be the only file able to access all the other files/directories.
I have seen other solutions here on StackOverFlow but they do not match above requirement.
Laravel has it's own .htaccess ready and that should work with your shared hosting too..
myfoldersite/public/.htaccess
move to
myfoldersite/.htaccess
and rename
myfoldersite/server.php
to
index.php
And try browsing your site again, let's see if that works.
Cheers!
You can block an access to a folder with this code in the .htaccess
<Directory "/file/">
deny from all
</Directory>
You have to modify the "file" by the name of your files.
But I do not know if that's what you're looking for so you can do this too:
RewriteEngine on
RewriteRule ^(.+)$ index.php
We have recently moved a Magento multi site environment to a new dedicated server, however all the sites apart from the admin URL site (not used apart from admin are) are reporting Magento style 404 pages on the front end.
We have ensured mod_rewrite is turned on, checked the database and manually amended the URLs in PHPMyAdmin to assign some temporary test URLs. The URL assigned to the admin area works fine, and the rest resolve to the server, however every front end is still 404. We have tried adding in index.php to the URL, no change. Checked all file and folder permissions, all OK. Cleared all cache manually and reindexed from command line. No change.
We have checked HTACCESS is correct which it looks to be. We have even taken another backup of the database and full site and restored to another server with the same issues.
We have also tried disabling SEO urls/URL Rewrites without change too.
Error logs dont say a lot either which isnt helpful.
Really struggling with this now so any help or pointers greatly appreciated. Thanks
First Solution:
Replace current .htaccess file with the default .htaccess file from Magento.
Second Solution:
#fastcgi_param MAGE_RUN_CODE default;
If doesn't work, try following solution:
Third Solution:
Is this installed on an Apache webserver? If not, the .htaccess functions will need to be translated to your flavor of web server software.
Has DSO module for mod_rewrite been installed in Apache and been enabled to load?
Is AllowOverrides enabled for the virtual server so Options +FollowSymLinks will function? You may have to check with your hosting service provider and have it enabled.
Is Magento's .htaccess file available in the doc root folder?
Has the rewrite engine been turned on in the .htaccess file?
Has the proper RewriteBase been assigned in the .htaccess file?
General entries in Magento's .htaccess that must function so rewrites will function to eliminate the need for index.php to appear in the URL.
<IfModule mod_rewrite.c>
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
############################################
## you can put here your magento root folder
## path relative to web root
#RewriteBase /magento/
############################################
## workaround for HTTP authorization
## in CGI environment
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
</IfModule>
Third solution from Fiasco Labs
How do I restrict my local.xml from being seen by outsiders, as in Magento's app/etc/local.xml which has all the database access information.
Please specify the file paths where i need to make changes,
thanks
http://www.domainname.com/app/etc/local.xml is forbidden by .htaccess of magento with default setting. Please check your .htaccess.
If you don't have htaccess file you can get .htaccess.sample , just rename it by .htaccess
All the request in magento or any mvc structure website goes to index.php page. If you see .htaccess file of magento carefully, you can get
RewriteRule .* index.php [L]
Allow access for images,skins and Javascript
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
So by default .xml files are forbidden (403)
If you are not running Apache, you need to find out how your chosen web server controls file access and translate the .htaccess files found in the stock Magento install to the control access method used.
If you're using Apache, you may need to turn on it's ability to read directory level .htaccess files. You then need to check and make sure the proper .htaccess files are installed in their directories.
For use under Apache Web Server, Magento extensively uses directory level .htaccess files to control access to its application folders, for example:
app/.htaccess
app/etc/.htaccess
should both exist and should contain
Order deny,allow
Deny from all
If they're missing, this is a sign that the developer designed the site on a WAMP stack and didn't understand how to set up FTP transfer to transfer hidden files. This also means that all the other .htaccess files are missing in critical areas like media/.htaccess which have even more necessary contents to shut off execution of php code out of potentially world writable directory trees (bad security):
Options All -Indexes
<IfModule mod_php5.c>
php_flag engine 0
</IfModule>
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
<IfModule mod_rewrite.c>
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
############################################
## never rewrite for existing files
RewriteCond %{REQUEST_FILENAME} !-f
############################################
## rewrite everything else to index.php
RewriteRule .* ../get.php [L]
</IfModule>
Basically, you need to download the Magento installer file and check its contents for all the missing .htaccess files that Magento puts in its various directories to control access.
Apache web server is running under Windows 7 professional. Apache version is Apache/2.2.17 (Win32) PHP/5.3.8. mod_rewrite is loaded according to phpinfo(). <VirtualHost> tag contains RewriteLog and RewriteLogLevel 3 directives. Log file set in RewriteLog directive is created.
.htaccess file in root directory is following:
RewriteEngine On
RewriteRule ^alice\.html$ bob.html
Current directory contains bob.html file and it can be opened with localhost URL.
But alice.html URL can not be opened, it causes error 404.
Log file for this site contains just normal message about file not found.
Rewrite log file exists but empty.
Which can cause rewrite directives being ignored?
Make sure you have this line in your httpd.conf:
AllowOverride All
AllowOverride controls what directives may be placed in .htaccess files.
Testing: To test whether .htaccess is enabled or not, just put some junk text in it and see if it generated a 500 internal error or not.
How to enable directory and file listing in XAMPP ? In WAMP it is by default enabled.
My Xampp httpd.conf already had the Indexes option under the xampp directory entry
Removing all the default #comment lines, it looks like this:
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
But, I have my local root mapped to a different directory, outside of 'htdocs', (as per this post Make XAMPP/Apache serve file outside of htdocs ) so to enable this for all directories, I had to find the entry just above that, and add the word "Indexes" to it.
<Directory />
Options FollowSymLinks Indexes
AllowOverride None
Order deny,allow
Deny from all
</Directory>
Note I would never enable this for all directories on a production server, but locally it is quite useful.
Just delete or rename index.html and index.php files
There is a XAMPP Directory Browsing UI app, that will help you to browse projects inside htdocs in XAMPP.
Open apache/conf/httpd.conf and search for Indexes in httpd.conf
And comment complete line like this:
#Options Indexes FollowSymLinks Includes ExecCGI
#Options - Indexes FollowSymLinks Includes ExecCGI
Uncommenting First will enable the indexing of directories.
Uncommenting Second will disable indexing of directories
Removing the comment will enable the Directory/file listing of hosted path.
Rename the 'index.php' file that sits in your htdocs folder to something like 'MODIFIED_index.php' (if you want to be able to revert to it later) - this index.php file is only used to point to xampp's admin controls that are found in 'localhost/xampp/' anyway.