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/
Related
I am trying to shorten my website url of a newly added page event like
mysite.com/asoebi/myevent instead of mysite.com/asoebi/index.php?event=myevent
but every time i try to change my .htaccess file it give an error
here is .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^index/(\w+)$ ./index.php?event=$1
</IfModule>
You have to enable mod_rewrite in apache for this to work.
Put this one in the .htaccess file in the /public_html/asoebi/ folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /asoebi/
RewriteRule ^(.*)$ index.php?event=$1 [L]
</IfModule>
Also remove the last rewriterule from the main htaccess file you posted above
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^read(.+)?$ /read.php?id=$1 [QSA,L]
RewriteRule ^chapter(.+)?$ /readchapter.php?id=$1 [QSA,L]
RewriteRule ^list(.+)?$ /list.php?id=$1 [QSA,L]
</IfModule>
Above is my htaccess file, I trying create a story reading website.
I trying to shorten example link of
http://read.mydomain.com/chapter/three_little_fox/
So when it query
/chapter/three_little_fox
It will actually load readchapter.php?id=three_little_fox
But when I try load the page
http://read.mydomain.com/chapter/three_little_fox/
It throws a Internal 500 error.
Thanks for helping
The current .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^chapter/([^/]*)$ readchapter.php?id=$1 [L]
</IfModule>
But the 404 error exist, my folder is this way
.htaccess
readchapter.php
index.php
Try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^chapter/(.*)/?$ /readchapter.php?id=$1 [QSA,NC,L]
</IfModule>
RewriteCond (Rewrite Conditions) ensures that if the request is already for a file or directory, RewriteRule will be skipped.
This will work for you:
RewriteEngine On
RewriteRule ^chapter/([^/]*)$ /readchapter.php?id=$1 [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.
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