Htaccess remove filename from url - .htaccess

I would like to remove the single.php ? how would i go about this ?, i have tried the following:
so EG. www.mysite.com/single.php/contact/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [QSA,NC,L]
</IfModule>

You can use these rules:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ single.php/$1 [L]

Related

how to rewrite GET param using htaccess

I need to rewrite the url:
https://pieskowato.pl/posts.php?post=param
to
https://pieskowato.pl/posts/param
i found the htaccess config and it works at localhost but not in production..
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{DOCUMENT_ROOT}/$1 -f
RewriteRule ^[^/]+/([^.]+\.(?:js|css|jpe?g|png|gif))$ /$1 [L,R=301,NC]
RewriteRule ^/post/([^/]*)$ /post.php?post=$1 [L]
url https://pieskowato.pl/post/dlaczego-warto-adoptowac-psa
Hosting OVH.com
With your shown samples, could you please try following.
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{DOCUMENT_ROOT}/$1 -f
RewriteRule ^[^/]+/([^.]+\.(?:js|css|jpe?g|png|gif))$ /$1 [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{DOCUMENT_ROOT}/$1 -f
RewriteRule ^(post)/([^/]*)$ /$1.php?post=$2 [NC,L]
Have it this way:
# important to turn off MultiViews
Options -MultiViews
RewriteEngine On
# fix css/js/images
RewriteCond %{DOCUMENT_ROOT}/$1 -f
RewriteRule ^[^/]+/([^.]+\.(?:js|css|jpe?g|png|gif))$ /$1 [L,R=301,NC]
# handle /post/anything
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/([^/]+)/?$ post.php?post=$1 [L,QSA,NC]

How to rewrite the website URL in .htaccess

is there a way to replace an url with the .htaccess like this:
http://website.com/file.php?watch=video
to this one:
http://website.com/file/watch/video
Tried with this,and haven't worked.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/watch/([\d]+)$ $1.php?watch=$2 [L]
My .htaccess file:
#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]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/watch/([\w-]+)$ $1.php?watch=$2 [L]
Have it this way:
RewriteEngine on
RewriteBase /test/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /([\w-]+)\.php\?watch=([^\s&]+)\s [NC]
RewriteRule ^ %1/watch/%2? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/watch/([\w-]+)$ $1.php?watch=$2 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

Remove question mark from url using htaccess

I want to redirect the url : https://WEB_URL/video?id=1 to https://WEB_URL/video/1
and I have written following htaccess code but it is not working :
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^video/([^.]*)$ video?id=$1 [QSA,L]
My full htaccess code is as follows:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine On
ErrorDocument 404 /login.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# To externally redirect /dir/abc.php to /dir/abc
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)/?$ $1.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^video/([^.]*)$ video?id=$1 [QSA,L]
</IfModule>
why it is not working ? What I am doing wrong please help me on this.
Thanks in advance.
Try this:
ErrorDocument 404 /login.php
Options -MultiViews
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /video(?:\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /video/%1? [R=302,L,NE]
# To externally redirect /dir/abc.php to /dir/abc
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^video/([^.]+?)/?$ video.php?id=$1 [QSA,L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]

Multiple conflicting htaccess RewriteRules

I'm trying to have both people's profiles at example.com/Sara and a few special pages like example.com/home and /account.
How do I make both of my RewriteRules work?
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./people.php?s=$1
RewriteRule ^home ./home.php
Thanks!
Edit:
Figured it out...!
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./people.php?s=$1
Figured it out...!
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./people.php?s=$1

Htaccess Problem in PHP

How can I rewrite
www.example.com/test.php?search=demo
to
www.example.com/test/?search=demo
using htaccess
Put that into your .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9]+)/?$ $1.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Resources