I want to remove the .php extension from the url by htaccess file . please let me know How can I do it ??
url:http://domain name/profile.php
I want like this
url:http://domain name/profile
You need to read up on it in order to be able to write regular expressions and use .htaccess in different ways, but a simple rewrite would look like this:
RewriteEngine on
RewriteRule ^profile$ profile.php [L]
If you wanted to globally remove all of .php extensions but retain the filename, you'd need a regex that looked something like:
RewriteRule ^([a-zA-Z0-9\-_]+).php$ $1.php [L]
Related
I Want to rewrite the url using .htaccess
Plz Read the code, and you well Get to know What I mean
My URL :
article.php?id=1&title=example
Using this in .htaccess
RewriteRule ^article/([0-9]+)/([0-9a-zA-Z_-]+)$
article.php?id=$1&title=$2 [NC,L]
I get
article/1/example
What i need is
article/example
So something like this:
RewriteRule ^article/([0-9a-zA-Z_-]+)$ article.php?title=$1 [NC,L]
I want to rewrite the url in my project.
For example:
http://www.example.com/dashboard/test/ to http://dashboard.example.com/index.php
Also I want to do it for:
http://www.example.com/dashboard/test2/ to http://dashboard.example.com/index.php
Can anyone tell me the idea to rewrite the url?
First you create a .htaccess file in your root.
Than, just put the redirect commands in it.
How to compose a .htaccess and how to create rewrite rules is explained here: http://net.tutsplus.com/tutorials/other/the-ultimate-guide-to-htaccess-files/
You will need something like:
RewriteRule ^(.*)$ http://dashboard.example.com/$1 [L,QSA]
try this
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^test.*$ http://dashboard.example.com/index.php [R=301,L]
Given the PHP URL course.php?id=10 I want it to redirect to course.html and I want to use the id=10 on this page. How can I do this?
You can't cleanly rewrite the url and not include the variable somewhere. You'll need to do something like so:
RewriteRule ^([0-9]+)/([^.]+)\.html $2.php?id=$1 [L]
Which will work for http://example.com/10/course.html.
Create a .htaccess file and add the following:
RewriteEngine On
RewriteRule ^([^.]+)\.html$ $1.php [L]
Upload this to the root of your files (most of the time it's /var/www/ or /home/user/public_html/.
I want to pass variable in .html extension pages and .html pages are made up of mod rewrite so these are not html files but php script which are made .html through mod rewrite.
any clue?
EDIT: My .htaccess file*:
RewriteEngine on
RewriteRule ^watch/(.*)/(.*).html$ video.php?tag=$1&video=$2 [L]
RewriteRule ^(.*)/([0-9]+).html$ index.php?tag=$1&page=$2 [L]
RewriteRule ^(.*).html?([a-zA-Z=]+)$ index.php?tag=$1 [L]
* As supplied in the comments. Spacing may be different than the original.
Add the [QSA] flag to your rewrites. That will take the original query string and add your new params to it.
RewriteRule ^(.*).html$ index.php?tag=$1 [L,QSA]
This will rewrite whatever.html?orderby=views into index.php?tag=whatever&orderby=views.
The only catch is, with PHP anyway, whatever.html?tag=somethingelse will give you some weirdness. ($_GET['tag'] will have two values, but only the one that shows up last will be the real value.) But that's generally fine; you just have to be sure not to provide URLs like that, and you can just not care what people trying those wacky URLs see. (Assuming, of course, that you validate $_GET['tag'] properly.)
Hi i am using Codeigniter PHP framework.
Is there is any way to display .html extension rather than .php extension in URL?
Set your url suffix on your config.php found here
/application/config/config.php
$config['url_suffix'] = '.html'; //# line 60ish
I haven't actually tried it myself but see the section Adding a URL Suffix in this part of the user guide.
Just add following to Apache's config and it will process .html files with PHP:
AddType application/x-httpd-php .phtml
With that you can rename your .php files to .html.
Or you can use mod_rewrite to handle this on the fly
use a .htaccess file that does a url rewrite .html to the equivalent .php
if you are using codeigniter you should even be thinking of hiding any extension altogether.
If ur using APache. You can use URL Rewrite Rule.
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
As others said, creating a .htaccess file will allow you to rewrite .php to .html. The following code should do the trick:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L]
I am interested as to why you actually want to do this though. Codeigniter, by default, uses a segment based approach which is friendly and does away with query strings and file extensions. Using another htaccess rule, you can remove index.php from the url to make them even cleaner:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
So your urls can look like this: example.com/home, example.com/about etc. This is much prettier than having a file extension in the url.
More information about codeigniter URLs can be found here: http://codeigniter.com/user_guide/general/urls.html