Why RewriteRule in .htaccess does not have effect? - windows

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.

Related

Public url issue in aws in laravel

I have hosted my site on aws through ftp,
now when i access this
url : http://X.XXX.XXX.X/projectfoldername/
i can access the page after i use
http://X.XXX.XXX.X/projectfoldername/public
but i want to remove public changed htaccess file also but when i upload it on cpanel it is working.
.htaccess file :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
</IfModule>
Any help is highly appreciated
Nearly all Linux OS's have a .conf file that you can use to tell it which folder is the public folder. This needs to be updated for Laravel to work.
From here (https://bobcares.com/blog/cpanel-change-root-directory/), for cPanel:
4. Updating cPanel files
cPanel/WHM does not have an option to change the document root of the main domain via any interface. By default it is the public_html folder in the user home directory.
In certain rare scenarios, we have customers who want their document root to be changed to another folder than public_html.
This has to be done from the backend by updating the cPanel user account file at /var/cpanel/userdata/username/domainname .
The following parameters are updated with the desired directories.
documentroot: /home/steinknu/public_html
scriptalias:
-
path: /home/steinknu/public_html/cgi-bin/
For sites with SSL installed, the configuration file for SSL is also updated accordingly.
This file is available at the location /var/cpanel/userdata/username/domain_SSL .
After making the changes, the user data cache is updated and Apache configuration file is rebuilt to reflect the changes in the corresponding files.
The Apache and PHP-FPM services are restarted and we verify the relevant configuration files to ensure that they are all updated properly.

Deny Access to all directory and file listing with .htaccess

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

Configuring CakePHP .htaccess for Cpanel ~temp/ URL

I'm trying to set up CakePHP 2.x in Cpanel (Hostmonster) while the domain of the site is still pointing to the older server. In order to pull up the site without the domain (for demo), I have to use http://[hosting-IP-address]/~mysite.
This is my default .htaccess file located in the root (the one before app/ folder):
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
If I leave it as it is, I get 404 error. When I remove the .htaccess file or leave it blank, the site content loads, but without CSS. The site files are located in /home2/mysite/public_html/ folder. I tried adding RewriteBase with different combinations (~mysite, mysite, mysite/public_html), but no avail.
I have tried with rewrite base setting then i get 500 internal server error. Please suggest
Instead of changing your site .htaccess code. I will suggest you update your local pc host file to point your site to new server, so that you can check your all URL.
Open your hosts file which is located at : c:\Windows\System32\Drivers\etc\hosts and add the following code with your new hosting IP address
hosting-IP-address www.domain.com
hosting-IP-address domain.com

How do I restrict my local.xml from being seen by outsiders,

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.

Where do I put RewriteRules in Apache2 without using .htaccess files?

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

Resources