I have the following in my .htaccess which basically removes .php extensions from url and redirects user to the url without the .php extension. However, if i have a querystring for lets say account.php, it will be account?user=john&id=12, I would like my htacess code below to be abe to let convert the querystring to forwardslashes.
Any ideas how I can do this? Thanks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
Create a .htaccess file with the code below
RewriteEngine on
RewriteRule product-categoryid-(.*)-productid-(.*)\.htm$ Your Root URl?categoryid=$1&productid=$2
Your Root URl
Root URL means like wwww.google.com/
Related
I have a php project using a directory structure and I want to create pretty urls.
Basically I want to remove ".php" extension of each file and delete path stuff between localhost and the filename.
Example:
transform this => localhost/myproject/views/pages/login/login.php
into this => localhost/myproject/login
I know I have to configure .htaccess mod_rewrite but I don't know how exactly to be honest.
Try and add this to your .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
It should basically remove all the .php extensions from being showed.
Okey, I've solved it. I have a index.php file in the root folder so any url will redirect to that file adding RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] in .htaccess using a query string with the view name I want to show. Then I had to rewrite all links to look like "/myproject/name_of_the_view" inside of the project
I'm new on php programming and i'm customizing an CRM base on PHP. I want to change the .php extension in .aspx, whether the php script is in the root file or sub directory, the .aspx should show up.
Here is my URL
I want to change THIS:
http://localhost/edev/pages/UI.php?operation=req
Into:
http://localhost/edev/pages/UI.aspx?operation=req
the code that i have tried
.HTACCESS
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://localhost/test/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://localhost/test/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
Let me know if you have any question according to this question. Thank You :)
Try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.aspx$ $1.php [L]
Recently I was thinking of making some seo friendly urls by rewrite and redirecting urls.
the rule which I wrote is working fine for this type of url like xyz.com/abc.php this automatically got converted into xyz.com/abc now I need help with this type of urls abc.com/study.php/abc/123 which I want to redirect on abc.com/study/abc/123
my .htaccess file is
RewriteEngine On
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
EDIT.
It was working fine now I have changed my mind that instead of removing .php extension from all files I want to remove .php extension specifically from 2 files i.e a.php and b.php.
You can tweak your existing rules to support this PATH_INFO as well like this:
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\s/+(\S+?)\.php(/\S*)?\sHTTP [NC]
RewriteRule ^ /%1%2 [L,R=301,NE]
# check to see if the request is for a PHP file:
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^/?(.+?)(/.*)?$ /$1.php$2 [L]
I have very poor knowledge about .htaccess
Goal:
Param can be set before index like: www.example.com/param/index
. Param also can not be set (www.example.com/index).
In php i need get this param something like $_GET['param']
Orginal file structure are: www.example.com/index.php
Note. Index.php can by any file
Now i have
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
How to remove .php extension at filename end. How to continue this?
www.example.com can by any http, https, non-www, www domain
If I interpret the question correctly, you can use these rules in your root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^([^/]+)/?$ $1.php?param=en [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/$2\.php -f [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ $2.php?param=$1 [L,QSA]
How can I Replace .php with .html ?
I have all files with .php extension in my files directory
/files
foo.php
bar.php
I want browser to show them as
http://example.com/files/foo.html
http://example.com/files/bar.html
Is this possible by .htaccss?
Add this to your files/.htaccess
RewriteEngine on
RewriteBase /files/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /files/$1.php [NC,L]
this rewriteRule will redirect all .html requests to .php meaning that if you enter www.example.com/files/foo.htmlthen it will be internally redirected to www.example.com/files/foo.php and your browser will remain at www.example.com/files/foo.html
You need to use URL Rewrite on your .htaccess file, there is a post with the same question and is solved already here :
Rewrite
Try this
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]