This is where the PHP files are:
ts1.WEBSITENAMEHERE.biz/cp/
The .htaccess file is also in this folder.
I want to remove the '.php' from 'FILENAME.PHP'.
This is my current '.htaccess' file:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /cp
RewriteRule ^(.*)/$ $1.php
But it is not working. Why is this?
RewriteEngine on
RewriteBase /cp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule .* $0.php [L]
Create a .htaccess file in the DocumentRoot dir.
Add the following code in that file...
##############
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(.*)\.(.*)$
RewriteRule ^(.*)$ %{REQUEST_URI}.php [R]
#############
mod_rewrite should be enabled for this to work.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /cp
RewriteRule ^(.*) $1.php
I use this checker: http://htaccess.madewithlove.be
Related
I'm trying to hide URL id
from
http://localhost/download/view.php?s_id=T7bPo
to
http://localhost/download/view/T7bPo
ReWriteEngine On
RewriteRule ^view/([0-9]+) view.php?s_id=$1
I tried many lines of code like
RewriteRule ^view/([^/\.]+)?$ /view.php?s_id=$1 [L]
RewriteRule ^view/+?$ /view.php?s_id=$1 [NC,L]
But failed everytime
Error
Object Not Found
As you can see below
If your .htaccess file is in /download/ folder check this rule on top of your rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^view\/(.*)$ /view.php?s_id=$1 [L]
</IfModule>
If your .htaccess file is in / website root folder check this rule on top of your rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^download\/view\/(.*)$ /download/view.php?s_id=$1 [L]
</IfModule>
#remove php file extension-e.g. https://example.com/file.php will become https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
from https://www.plothost.com/kb/how-to-remove-php-html-extensions-with-htaccess/
I would like to change "/" to "/folder".
So when user clicks link with this url "/page.php" I want it to be automatically translated by .htaccess to "/folder/page.php".
How can I achieve this?
This simple rule should work for you in site root .htaccess (parent directory of folder):
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/ [NC]
RewriteRule .* folder/$0 [L]
Please use .htaccess file. i think its better for you.
Your Need is:
HTTP://YOUR_DOMAIN.COM/page.php
TO
HTTP://YOUR_DOMAIN.COM/FOLDER/page.php
Step1:
create an .htaccess file on your Server
Filename: .htaccess
just Copy this part and Change the Values.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} YOUR_DOMAIN.COM$ [NC]
RewriteCond %{HTTP_HOST} !FOLDER
RewriteRule ^(.*)$ http://YOUR_DOMAIN.COM/FOLDER/$1 [R=301,L]
Reference-1 |
Reference-2
Try this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/$1 [QSA,PT,L]
RewriteRule ^$ /folder/$1 [QSA,PT,L]
RewriteRule ^index.php/(.*) $1 [QSA,R,L]
</IfModule>
New .htaccess file (still not working, it sends me to localhost/xampp
RewriteEngine on
RewriteBase /sample/
# set root to index.php
DirectoryIndex index.php
# prevent directory listing
Options -Indexes
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index.php$ $1 [R=301,L,NC]
# removing extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)/?$ $1.php [L]
Old .htaccess file below:
RewriteEngine on
# set root to index.php
DirectoryIndex index.php
# prevent directory listing
Options -Indexes
# removing extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# remove index.php
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://localhost/sample/ [R=301,L]
Domain is http://localhost/sample/. I have tried many things that Google has given me but none of them work. Every time I go to localhost/sample/index.php it doesn't redirect to localhost/sample/. I also used the Redirect 301 /index.php /.
I tried
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
But it sends me to http://localhost/xampp/splash.php.
I am still new to .htaccess so I really don't have any idea what I am doing wrong. I've tried the answers that have been given to the questions where the OP said the answer worked.
You can use:
# set root to index.php
DirectoryIndex index.php
# prevent directory listing
Options -Indexes
RewriteEngine on
RewriteBase /sample/
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index.php$ $1 [R=301,L,NC]
# removing extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)/?$ $1.php [L]
RewriteBase /sample/ is needed to make sure redirect happens from raltive path of current directory.
Use this:
RewriteEngine On
# prevent directory listing
Options -Indexes
# allows leaving off the extension (.php) in urls
Options +MultiViews
# removing extensions
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^index(\.php)?$ http://localhost/sample [R=301,L]
i got a problem with rewriting my edit.php?id=1 to edit/id/1. Right now i have the following in my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^edit/id/([^/.]+)$ edit.php?id=$1 [NC]
This doesn't change the url. Can something see what i do wrong?
You need one additional rule to change the URL externally. This should be placed in root .htaccess:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/([^/]+)/edit\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1/edit/id/%2? [R=302,L,NE]
RewriteRule ^([^/]+)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L,QSA]
Give this a try and see how it works for you.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L]
</IfModule>
OR you can do this if you only have a couple of directories the same. The will go in the root .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(profiles|customers|test)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L]
</IfModule>
I am new to htaccess file and have the following requirement.
I have a dynamic page which handles like this
com/index.php?postname=products
.com/index.php?cat=news&country=india
for these pages I want SEO friendly urls like this
.com/products/ to .com/index.php?postname=products
.com/news/country to .com/index.php?cat=news&country=india
What code do I need to put it in htaccess file?
Do I need to write RewriteCond or RewriteRule or both?
If possible please give me the sample code to do this.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?postname=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?cat=$1&country=$2 [L]
Try this Example for your work.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^postname=(.*)$
RewriteRule ^index\.php$ /postname/%1? [R=301]
RewriteRule ^postname/([^-]+)$ /postname.php?id=$1 [L]
The above code will redirect
index.php?postname=products
to
index/products
Here is the htaccess code that helps you
Save the line .htaccess in your index.php folder or root folder.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([A-Za-z0-9_\-]+)$ index.php?postname=$1 [L]
RewriteRule ^([A-Za-z0-9_\-]+)/([A-Za-z0-9_\-]+)$ index.php?cat=$1&country=$2 [L]
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_gzip.c>
mod_gzip_on No
</IfModule>
It works fine for me.