How to hide php extension in url? - apache

I am trying to remove php extension from url, But its not working for me. I am using Windows 7, with apache2.2.17 and php5.3. Now I have configured it as
in .htaccess file
OPTIONS -Indexes
IndexIgnore *
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
in httpd.conf enabled mod_rewrite as
LoadModule rewrite_module modules/mod_rewrite.so
and
<Directory "D:/Apache/htdocs">
Options Indexes FollowSymLinks ExecCGI MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
in php.ini
expose_php = On
After making these configuration still i am not able to remove php extension from url in my windows machine but same thing is working in ubuntu server.
Is there anything I am missing here?

This might answer your question:
RewriteRule ^/([^-]*)$ /$1.php
It works for root catalog.
RewriteRule ^catalog/([^-]*)$ catalog/$1.php
Or you can write automatic script:
RewriteRule ^/([^-])/([^-])$ /$1/$2.php
But this is for "httpd.conf" file.
Where: ([^-]*) means variable; $1, $2 means converted to variable i.e.
www.verity.com/foo/bar => verity.com/foo/bar.php

Use this instead:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php
By doing this, you will be able to call example.com/abc.php as example.com/abc

Related

how to rewrite example.com/abc.html to example.com/abc

I am trying the below code but not working for me
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Simple solution, enable MultiViews in Apache.
MultiViews hides the file extension in the URL.
<Directory "/folder/subfolder/subfolder">
Options +MultiViews
</Directory>

url not found error in laravel

I am using Laravel 5 with a new version of apache on ubuntu and when I try to access the page: localhost it works and if I try localhost/index.php/my_page it works but if I try localhost/my_page, it doesnt. So from searching other questions I guess my problem lies in the .htaccess file.
As per suggestions I saw online I added the rewriteBase and Options +FollowSymLinks to my .htaccess in laravel/public:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /repos/kenrose/public
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and this is what my apache2.conf file looks
<Directory /repos/kenrose>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
I've taken all the suggestions i've found about this issue. What is the problem?
Try this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Try to remove ur +FollowSymLinks part,hope it will work.
after running
a2enmod rewrite
in the command terminal, all is well.
I don't know what this does, or what the problem was though.

.htaccess rewrite rule with DocumentRoot subdomain

I'm trying to implement some htaccess rewrite rules. However in not a pro in htaccess.
I have a subdomain gateway in (as described in: .htaccess and rewrite sub domains)
Now i would like to use SEO friendly URL's. The gateway has some subfolders i.e. email in this case.
http://gateway.example.com/email/Param1/Param2/
This url should be rewritten to http://gateway.example.com/email/index.php?hash=Param1&hash2=Param2.
In the email folder I have created a .htaccess file with the following contents:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]
RewriteRule ^/(.*)/(.*)/ index.php?hash=$1&hash2=$2
When requesting the http://gateway.example.com/email/Param1/Param2/ i'm now getting a 404. What is wrong with the rule?
You should do it this way
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([^/]*)/([^/]*)/ /email/index.php?hash=$1&hash2=$2 [L]
you can try this.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^/([^/]*)/([^/]*)/ index.php?hash=$1&hash2=$2
*you need to configure apache(httpd) to accept UrlRewrite by changing AllowOverride from non to all like this :
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>

htaccess - Options FollowSymLinks or SymLinksIfOwnerMatch is off issue

im using plesk for hosting my webpage. And evertime when im opening the root domain (e.G: "xxxxxx.xx"), my vServer is logging following error:
Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/vhosts/xxxxxx.xx/httpdocs/index.pl
I do not have index.pl file in httpdocs.
And this error occurs not, when i call "xxxxxx.xx/index.php" or other pages.
My htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^products/(.*)/(.*)/$ products.php?id=$1&p=$2 [QSA,L]
RewriteRule ^static/(.*)/(.*)/$ static.php?id=$1 [QSA,L]
RewriteRule ^index\.php$ - [L]
Any ideas, how i can solve this problem?
I know this may not sound right but in your plesk domain settings make sure cgi support is checked but perl support is unchecked. I could not get my 403 forbidden errors to go away when using mod_rewrite rules even with a modified Apache conf file. Once I unchecked the perl option in the plesk config for the domain perl rewrites work.

Codeigniter wont redirect in netbeans

I have got this url:
http://localhost:85/WebCamClone/Home
But it will only load like this:
http://localhost:85/WebCamClone/index.php/Home
I tried to put htaccess rule like this one:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
But it didnt work. What else should I try?
This is what is inside my apache config file:
<Directory />
Options FollowSymLinks
AllowOverride all
Order deny,allow
Deny from all
</Directory>
In application/config/config.php have you removed index.php from $config['index_page'] so that it looks like:
$config['index_page'] = '';
Try with this code once in your .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
The problem was in apaches config file.. I had to go to its file and replace allowoveride none to allow override all