RewriteRule without FollowSymLinks or SymLinksIfOwnersMatch - .htaccess

I'm running into some problems with rewriting my URLs.
Recently moved to a new host where FollowSymLinks and SymLinksIfOwnersMatch is not allowed as options in my .htaccess file. Using these will give me a 500 error. Mod_rewrite is however enabled on the host.
Normally my rewriting code looks like the code below and works perfectly:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^link/(.*)$ link.php?urlkey=$1 [QSA]
But with removing +FollowSymLinks the rewriting doesn't work.
Any idea what I'm missing here?
Thanks in advance for your help.
EDIT
In the Apache docs (mod_rewrite - Appache HTTP Server Version 2.4) is stated that:
To enable the rewrite engine in this context, you need to set "RewriteEngine On" and "Options FollowSymLinks" must be enabled. If your administrator has disabled override of FollowSymLinks for a user's directory, then you cannot use the rewrite engine.
There must be a way to write pretty URLs even when FollowSymLinks is off right..?

Related

.htaccess second RewriteRule note working

I have a PHP page like example.com/new/info.php?title=example. The .htaccess is in folder /new/. I tried it in the main directory also. My .htaccess looks like this:
ErrorDocument 404 /404.php
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ page.php?title=$1 [QSA,L,NC]
RewriteRule ^info/([a-zA-Z0-9_-]+)/$ info.php?title=$1 [QSA,L,NC]
The first Rule is working, but the second sends no GET['title'] to the server. The site info.php loads but without the variable. I have tested it on my localhost and it's working. I load it on my webspace and the second rule is not working.
I tried it also without new directory example.com/info.php?title=example and same not work.
What is my mistake?
It sounds like you have MultiViews enabled (possibly in the server config). You need to disable MultiViews for this to work. Add the following at the top of your .htaccess file:
Options -MultiViews
With MultiViews enabled, mod_negotiation will issue an internal subrequest for info.php when making a request for /info/example/ - before your mod_rewrite rule is processed, so no parameters are passed.

Can we use httpd.conf instead of .htaccess for clean URL?

I have read that setting changes in httpd.conf are much better as compared to making changes in .htaccess as the later one is parsed at Runtime while .conf is parsed at the time of starting Apache. So, is it possible to have all the .htaccess functionality in httpd.conf or there are a few things that have to done in .htaccess only.
Also, can you suggest how to debug clean URL issues?
Basically, I am not able to get the clean URL working. I can access the show.php file but am not able to access the GET variables. Here is the .conf settings.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/show/([^/\.]+)/([^/\.]+) http://www.example.com/show.php?id=$1&img=$2 [L,R]
I have also added
Options Indexes MultiViews FollowSymlinks
AllowOverride All
in <Directory "/var/www/html">
Thanks.
As stated in the Apache manual on .htaccess, anything you can put in an .htaccess file can be put inside a <Directory> block within httpd.conf for better efficiency.
As for your issues with rewriting the URL, your first RewriteCond appears to only be matching URLs that aren't www.example.com (the ! in front is a negation modifier). Remove the ! and see if that fixes the issue. (You probably should remove the second RewriteCond as well, until you have the first one matching; otherwise, debugging problems will be more difficult.)

Can't remove index.php on CodeIgniter2.1.2 with RHEL

I have followed from many links to solve this problem. However, It doesn't work with my project.
Move .htaccess file to CI root directory
Config about mod_rewrite in .htaccess file (all structures that I found on the Google)
change config[‘index_page’] to an empty
Set config['uri_protocol'] = 'REQUEST_URI' or 'QUERY_STRING'
then, it shown
Not Found The requested URL /class/method was not found on this
server.
I don't know how to fixed it further. I spent so long time for this problem.
Install a fresh copy of CodeIgniter
Change $config['index_page'] to = '';
Copy this to your .htaccess
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Visit http://yourhost/codeigniter/welcome/index.
Does it work? If not, change the last line of the .htaccess above to
RewriteRule ^(.*)$ /index.php/$1 [L]
If it does not work at this point, check if your Apache supports mod_rewrite and it is enabled.
Ensure that mod_rewrite is enabled: If you're running Ubuntu open a terminal and type sudo a2enmod rewrite.
Furthermore, ensure that your .htaccess file is even being parsed. Again, on Ubuntu locate: /etc/apache2/sites-available/default and modify the <Directory> directive to:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Google search to find related Windows/Mac commands and file locations.

simple .htaccess rule wont work in httpd.conf

Im trying to move a bunch of rewrite rules from a .htaccess file to a the apache config files, I get no errors and placed this within the VirtualHost section of the sites config file:
<Directory /var/www/da/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /
RewriteRule ^botswana/central-kalahari/$ /central-kalahari/ [R=301,L]
</Directory>
Rewrite Rules placed in server config / virtual host context will start with leading slash -- that is one of the differences from .htaccess behaviour. Therefore use this one:
RewriteRule ^/botswana/central-kalahari/$ /central-kalahari/ [R=301,L]

.htaccess: RewriteEngine not allowed here

I uploaded the .htaccess to the server and received an Error 500 (Internal Server Error).
And in the error log I had the following error:
.../.htaccess: RewriteEngine not allowed here
But mod_rewrite.so is enabled.
So, do I need to change
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
to
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
in the /etc/httpd/conf/httpd.conf file?
Or could it be something else? The .htaccess file should be okay, because it works perfectly fine on my localhost. I just don't want to screw anything up.
Here's part of my .htaccess file:
Options All -Indexes
Options +FollowSymLinks
RewriteEngine On
minimum configuration for your .htaccess to work:
AllowOverride FileInfo Options
allowing all configuration will work as well:
AllowOverride All
Let's say your DOCUMENT_ROOT is /home/foo/web then have this config in your httpd.conf file:
<Directory "/home/foo/web">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
This should take care of RewriteEngine is not allowed error you're getting.
Just an idea, this happened to me, and I've lost a lot of time trying to solve it.
If you have a directory like d:/web/my-sites/some-site/
And you place the .htaccess on d:/web/my-sites/some-site/.htaccess (where it supposed to be).
If you have ANY .htaccess files before this directory, Apache reads that files, and blocks the execution of the entire path, producing an internal server error.
I.E.: You have d:/web/my-sites/.htaccess
In httpd version 2.4 (2.4.3 and 2.4.4), take a look at /etc/httpd/conf.d/wordpress.conf
There is one entry for:
....
Change:
"AllowOverride Options"
to
"AllowOverride All"
in wordpress.conf also in addition to changing httpd.conf. Restart the http server before the changes will take effect.
Also, just make sure you are editing the correct config file. I had created a file under /etc/apache2/users/USERNAME.conf but was editing /etc/apache2/httpd.conf.
Removing the USERNAME.conf file worked.
Try to change username.conf file on Mac under /etc/apache2/users/username.conf to
<Directory "/Users/akyoo/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
My .htaccess file looks like this
#Allow from all
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
This works fine for me.
Solution for Ubuntu users
I was getting this type of error from the Google Cloud instance after checking the logs from the /var/log/apache2/error.log
.htaccess: RewriteEngine not allowed here
To get rid of the above error & 500 Internal Server Error, follow these simple steps
sudo nano /etc/apache2/apache2.conf
Then add these snippets of lines
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After you’ve made that change, make sure to restart the server:
sudo service apache2 restart
This worked for me in getting rid of 500 Internal Server Error hosted on Google Cloud instance
you could use something like this in your .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|html|test)
RewriteRule ^(.*)$ /index.php/$1 [L]
this code simply means, that anything not pointing to index.php or html or test should be directed to index.php!
Hope this is helpful!

Resources