I have a htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I want to add the line below, but it gives me 500 error.
Options -Indexes
Can somebody help?
Check if the directory where your .htaccess lives in has enabled the neccessary AllowOverride (enabled must be: AuthConfig and Options at least) in the httpd.conf.
Make sure it is not within the
<IfModule mod_rewrite.c>
...
</IfModule>
part of your .htaccess
Usually you should have a logging-message in your error-log. I assume, that you will find something like this:
[alert] [client 192.xxx.xxx.xxx] /path/to/web/.htaccess: Options not allowed here
This solution does not always help (depending on the apache-version you are using): In some cases you have to move this section to your httpd.conf to make it work.
It is explained in detail in the apache-docs.
Related
I want to use mod_rewrite with Wampserver to remove "/index.php/" from addressbar. This code is suggested with Codeigniter Framework:
RewriteEngine on
#RewriteBase /
RewriteCond $1 !^(index\.php|img|table-images|robots\.txt|css|fonts|js|uploads|dbg-wizard\.php)
RewriteRule ^(.*)$ index.php/$1 [L]
This should change this url:
mysite.local/contact_us
to this:
mysite.local/index.php/contact_us
This works with XAMPP but with Wampserver first URL generates Error 404!
I enabled mod_rewrite with Apache and there is no errors in error log.
Update:
I added .blabla in .htacess but nothing happened! It means that Apache does not read .htaccess! Why?
I added AllowOverride All to httpd-vhosts.conf.
Apache did not execute .htaccess and enabling AllowOverride in httpd.conf is not enough.
This is my httpd-vhosts.conf file:
<Directory E:\mysite\www>
Options Indexes FollowSymLinks Includes ExecCGI
#Order Deny,Allow
#Allow from all
AllowOverride All
Require all granted
</Directory>
To check that mode rewrite is working or not try these steps:
Make a folder in your root directory called htaccess_test
Create a .htaccess file, and put these code into this and save it.
options +FollowSymLinks RewriteEngine On
RewriteBase /htaccess_test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ user.php?u=$1
Create one more file called user.php and put these code into
this and save it.
<?php
if(isset($_GET['u'])){
echo $_GET['u'];
}
Now go to browser type http://localhost/htaccess_test/put_some_value_here.
If that is working than the problem is not in your apache setting.
Make sure you are editing the right .htaccess file. The .htaccess file you need to edit is in your projects' root folder, not in application or any other folder. And put these code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /root_directory_of_your_project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I would like my url which is: http://localhost/slide-form/ad_posted.php?title=Cow%20Buffalo%20Gopal-1426356570
to look like : http://localhost/slide-form/ad_posted/title/Cow%20Buffalo%20Gopal-1426356570/
The below is the rule i have added in my htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ad_posted/title/(.*)/ ad_posted.php?title=$1
RewriteRule ad_posted/title/(.*) ad_posted.php?title=$1
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.html
</IfModule>
But I see no changes in my url. Any help is much appreciated. Thanks
Have this code in /slide-form/.htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /slide-form/
RewriteCond %{THE_REQUEST} /ad_posted\.php\?title=([^\s&]+) [NC]
RewriteRule ^ ad_posted/%1? [R=302,L,NE]
RewriteRule ^ad_posted/title/(.+)/?$ ad_posted.php?title=$1 [L,QSA]
There are two things need to attention:
Make sure you apache or other web server is already opened rewrite
module.
Check your configuration settings and ensure the directory where
.htaccess file located have the overwrite permission.
Like following settings:
I am using this apache rewrite, when i am on my local machine.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /skoleskak/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
But after i uploaded it, to my host i get server error. They told me they dont support Options, but i can't get it working without that.
I am trying to route my Silex installation, so its /web/stats/ instead of web/index.php/stats.
I found this example for Codeigniter http://www.chrishjorth.com/blog/one-com-codeigniter-htaccess-rewrite-rules/
Anyone know how to make it work with Silex?
Same problem at some hosters. If your server has installed Apache >= 2.2.16 you can use the FallbackResource command:
FallbackResource /index.php
in your .htaccess instead of
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /skoleskak/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
See also Apache’s fallbackresource: your new .htaccess command for more information.
I uploaded the current .htaccess file to a 1and1 server (actually 1und1.de, but I guess it's the same) and I'm geting a 500 Internal Server Error.
Options -MultiViews
RewriteEngine On
RewriteBase /lammkontor
RewriteRule ^categories/([^/\.]+)/?$ index.php?url=category.php&cat_url=$1 [L]
RewriteRule ^categories/([^/\.]+)/([^/\.]+)/?$ index.php?url=product.php&cat_url=$1&prod_url=$2 [L]
RewriteRule ^categories/([^/\.]+)/([^/\.]+)/recipes?$ index.php?url=recipes.php&cat_url=$1&prod_url=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+\.php)/?$ index.php?url=$1 [QSA]
This .htaccess works perfectly on my local MAMP server.
When I test the CGI-Monitor in the control-center with an example file I get
- cgi: File not present or has invalid modes
(no output)
The only file working now is index.php
Thanks for your help!
Actually I solved my problem adding a slash to the beginning of every Rewrite Rule, like:
RewriteRule ^(.+\.php)/?$ /index.php?url=$1 [QSA]
instead of
RewriteRule ^(.+\.php)/?$ index.php?url=$1 [QSA]
Thanks!
By default apache's htaccess rights are off or limited depending on your host.
I suspect its your Options -MultiViews causing the error.
Check your httpd.conf and check that MultiViews is allowed like below.
<Directory />
Options FollowSymLinks
AllowOverride Indexes Options=All,MultiViews
Order deny,allow
Deny from all
</Directory>
Just put a slash before the url. eg /index.php instead of index.php at the end of the rule
I'm just trying to figure out if I'm on the right path - additional details on rewriting the URL in my example would be appreciated.
I have installed a CMS program and would simply like that www.example.com be pointed to www.example.com/cms. I just want to know if URL rewriting through apache is the best way to accomplish this?
Thank you.
Just redirecting http://example.com/ to http://example.com/cms/:
<IfModule mod_rewrite.c>
RewriteEngine On
RewritRule ^/?$ /cms/
</IfModule>
Redirecting all urls which otherwise would've 404d to start with /cms/:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cms/$1 [L]
</IfModule>
Redirecting all urls to /cms/:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ /cms/$1 [L]
<Directory /var/www/html/cms/> #change this to the correct path
RewriteEngine Off
</Directory>
</IfModule>
That's definitely the approach I would take. I'm going to assume you're using Apache, though this can easily be done with IIS as well. You'll need to edit your .htaccess file in the root directory to do this using mod_rewrite.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ /cms/$1 [L]
</IfModule>
This should work for what you're after. Change "cms" to whatever directory you want to rewrite to.