I have a basic Rewrite rule defined in the root of my website, in an .htaccess file:
<IfModule mod_rewrite.c>
# http://www.generateit.net/mod-rewrite/index.php
# Tell PHP that the mod_rewrite module is ENABLED.
SetEnv HTTP_MOD_REWRITE On
RewriteEngine on
RewriteRule ^([^/]*)/$ category.php?cat=$1 [L]
RewriteRule ^([^/]*)/([^/]*)/$ post.php?cat=$1&post=$2 [L]
RewriteRule ^blog-([^/]*).php$ default.php?page=$1 [L]
</IfModule>
I have 2 sites hosted on the same folder structure:
DIR: example2.com
file: category.php
file: default.php
file: post.php
So the rewrite rule will redirect e.g.
example.com/post.php?cat=general-ledger&post=gl-journals-volumes
to:
example.com/general-ledger/gl-journals-volumes/
However, I have installed Wordpress in a folder called ddc on example2, but when I visit:
example2.com/ddc/wp-admin/user/
I can't view it, as the system thinks it's trying to view a rewritten page.
Is there any way I can stop the rewrite rule from firing for specific directories?
I have tried:
RewriteCond %{REQUEST_URI} !^/(example2.com|ddc)/?(.*)$ [NC]
But it made no difference. Furthermore, the error log shows this when I try to access the folder:
[Mon Jan 16 22:39:53.365334 2017] [autoindex:error] [pid 28997]
[client my_ip_address_here:53652] AH01276: Cannot serve directory
/home/oracle36/public_html/example2.com/ddc/wp-admin/user/: No
matching DirectoryIndex (default.php) found, and server-generated
directory index forbidden by Options directive
Your rewrite rules are not the problem. They only affect URLs with directories of one or two levels. Your problem is that you don't have index.php set up as a directory index, so there is nothing for Apache to serve from the WordPress directory. Add this to your .htaccess:
DirectoryIndex default.php index.php
I am adding default.php to that because the error message shows you have that set up already, and then adding index.php to it as another option, to support WordPress. You can remove your RewriteCond.
Related
I just transferred my website from example.com/newsite to example.com by moving the folder where everything was stored (newsite) into my public_html to make it the root domain. Now I am receiving multiple issues on my error_log and the website is loading very very slowly. The error log is telling me things like:
PHP Warning: current() expects parameter 1 to be array, boolean given in /home3/example/public_html/newsite/wp-content/plugins/lezada-addons/includes/templates/lezada_brands_grid.php on line 79
I was thinking the urls containing example.com/newsite should be rewritten via .htaccess
Will this resolve the problem? If so what would the rewrite code be? I tried:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com\newsite$ [NC]
RewriteRule ^(.*)$ "http://example.com/$1" [R=301,L]
</IfModule>
But this isn't working and the website is down!
I think somehow most of us had a trouble with .htaccess I d'like to know if someone can help me.
Opensuse 12.3 :
Code:
Linux linux-hyo0.site 3.7.10-1.16-desktop #1 SMP PREEMPT Fri May 31 20:21:23 UTC 2013 (97c14ba) x86_64 x86_64 x86_64 GNU/Linux
I d'like to install Cakephp on my machine but I have an error on my webpage saying that "
Code:
URL rewriting is not properly configured on your server.
"
my /etc/sysconfig/apache2 file as this :
Code:
APACHE_MODULES="authz_host actions alias auth_basic authz_groupfile authn_file authz_user autoindex cgi dir include log_config mime negotiation setenvif status userdir asis imagemap php5 reqtimeout authz_default rewrite"
and the /etc/apache2/sysconfig.d/loadmodule.conf as this line at the end
Code:
LoadModule rewrite_module /usr/lib64/apache2/mod_rewrite.so
I did also change my file etc/apache2/defaul-server.conf
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory "/srv/www/htdocs">
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order Allow,Deny
Allow from all
</Directory>
Any help?
on app/webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and on app/
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
This is quite an old question but maybe this answer is relevant for you Google users out there:
Did you change the View/Layouts/default.ctp?
This is what happens with this warning:
The warning is set in a div in View/Pages/home.ctp
In home.ctp only sets the warning when the file app/webroot/css/cake.generic.css exists
In the standard default.ctp layout, the stylesheet /css/cake.generic.css is loaded
In cake.generic.css the div with the warning is.... hidden!!!
So what happens when the default home page loads: it tries to load the cake.generic.css style sheet, which succeeds when mod_rewrite is configured correctly. So then the warning is hidden. If it fails to load the style sheet, the warning will stay visible.
This warning pops up, in short, when either there is a problem with mod_rewrite and htaccess, or you changed the layout so that the cake.generic.css is no longer loaded...
First check if you even try to load the stylesheet. Does it show up in your F12 console?
After hours trying to track down the problem I finally found that my .htaccess file never existed in the first place. I copied the following code into a new .htaccess file and hey presto.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Let me first say: I HATE CAKEPHP!!!!
I just spent hours working on this issue.
I learned that cake tests URL rewrite by checking for app/webroot/css/cake.generic.css
Make sure that exists.
My solution came after I checked the apache error_log and saw it complaining about not being able to find http:/myproject/css. Well, there is no css directory there by default. I created a link (ln -s app/webroot/css) and it solved Cake's problem.
If you got this error after new installation of Cakephp and you do not changed any of the files(css files or cake.generic.css) then do the following:
sudo a2enmod rewrite
sudo service apache2 restart
sudo nano /etc/apache2/sites-available/000-default.conf
Look for “DocumentRoot /var/www/html” and add the following lines directly below:
AllowOverride All
sudo service apache2 restart
Make sure you change all AllowOverride None to AllowOverride All
I have this problem and solve this copying the lines of cakebook:
http://book.cakephp.org/2.0/en/installation/url-rewriting.html
There is also a .htaccess file in the root folder, i.e. /.htaccess. This may not have been copied across as it's hidden by default by most operating systems.
Try adding this as the contents of /.htaccess and checking it makes it to the web server.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
There's more explanation at http://book.cakephp.org/2.0/en/installation/url-rewriting.html
There’s two solutions:
1) Either set the DocumentRoot in your Apache configuration file to the app/webroot/ directory, and CakePHP will use the .htaccess file there.
2) Place a .htaccess file in the root of your application, as by default I don’t think one gets created if you use the CakePHP console to generate an app. That .htaccess file should look this this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
I want to access my symfony app in production env (http://www.sample.com/amateur1/web/app.php) from this url http://www.sample.com/amateur1.
To do that I moved the .htacces file to http://www.sample.com/amateur1/.htaccess with this contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
But when I go to http://www.sample.com/amateur1 shows a 404 Error, and prod.log isn't written.
I also used RewriteBase /amateur1/web/ because I don't know If RewriteBase path is relative to the DocumentRoot of the server, Or from the path where the .htaccess file is located. Also tried /amateur1 and /amateur1/ as RewriteBase due to this answer Symfony2: How to deploy in subdirectory (Apache)
With the three try's, The Exceptions page appears unstyled, and not loading any image. But then I get the following error in prod.log file:
[2013-02-15 02:06:47] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /amateur1/" (uncaught exception) at /home/u105859802/public_html/amateur1/app/cache/prod/classes.php line 5121 [] []
What I'm doing wrong ?
In your configuration, apache uses public_html as the document root
If Symfony2 is installed in directory /home/u105859802/public_html/amateur1, the Symfony public directory to serve is /home/u105859802/public_html/amateur1/web/
You should use
RewriteBase /amateur1/web/
But beware, it is not safe
You have to protect your symfony directories! (configuration is accessible)
Why don't you try moving your symfony files in your private area ?
You can rename the Symfony web directory to public_html
See how to do that in documentation cookbook
So, my recommendation structure looks like below :
/home/u105859802/
vendor
src
app
bin
public_html (web by default in symfony2) <- the only public directory
In most of the shared hosting, you can't override Apache settings in that case may need to wright a redirection rule in .htaccess file
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule !^projectName/ /projectName/web/app.php/%{REQUEST_URI} [L,NC]
this is the rule I used in my project .
You may need to provide full paths to your assets other ways they will not get loaded .
I used the below to disable ,but my subdomains also not accessing .is there any code for only keeping for some folders ?
# disable directory browsing
Options All -Indexes
You can disable directory browsing using htaccess and mod_rewrite, and you'd be able to do it only under certain conditions. For example,in an htaccess file in the directory you want to disable directory browsing:
RewriteEngine On
RewriteCond %{HTTP_HOST} !subdomain.domain.com [NC]
RewriteRule ^$ - [L,F]
This will disable directory listing only if the host isn't subdomain.domain.com.
Or:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !123.45.67.89 [NC]
RewriteRule ^$ - [L,F]
This will disable directory listing only if the request isn't made from the IP: 123.45.67.89
Sounds like you put the code in a .htaccess file in your web root folder. You can instead use the same code in a .htaccess file in each of the folders you want to prevent directory browsing.
I want to rewrite all .php into .html,,, so i created a .htaccess file and added
AddHandler application/x-httpd-php .php .html .htm
but when it seems not working...
here i uploaded all files - http://www.fellowindian.com/ca/index.php & http://www.fellowindian.com/ca/page1.php
1: Do you have mod_mime installed on Apache.
2: Are you sure that .htaccess is executing.
Simple test would be to see if it can rewrite your urls to add / remove www from it.
Example:
Options +FollowSymLinks RewriteEngine
On RewriteBase / RewriteCond
%{HTTP_HOST} !^www\.mycee\.com$ [NC]
RewriteRule ^(.*)$
http://www.mycee.com/$1 [R=301,L]
3: Which user is the owner of the .htaccess file and what is its attributes?
4: Check that the AllowOverride directive is set in your apache config and not set to None.
Test by putting invalid directives in the .htaccess file and reloading the page.
If the apache error log doesn't show any errors, it's not executing.
5: If you're on shared hosting, check with your host if they have AllowOverride enabled or not.
Personally, I think the best place to put the AddType directive would be in apache's httpd.conf as .htaccess puts a performance hit on your server, but in the case of shared hosting, .htaccess is usually the only option available.
If you're trying to redirect something.php to something.html, you could do
RewriteEngine On
RewriteCond %{REQUEST_URI} .php$
RewriteRule (.*?).php $1.html