Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts

    How to convert php pages to html using .htaccess

    I want to ask if there is a way by using the .htaccess to convert the php extension in url to html without problems.

    for example of the url is like this:
    http://www.domain.com/videos.php?v=listvideo
    it change to be like this:
    http://www.domain.com/videos-v-listvideo.htm

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    You need to use Apache's mod_rewrite
    Add to your .htaccess file something like this
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} videos(.+)\.htm$
    RewriteRule videos-v-(.+)\.htm /videos.php?v=$1 [L,QSA]
    Last edited by poyzn; 01-10-2011 at 09:49 PM.

  • Users who have thanked poyzn for this post:

    Mido™ (01-11-2011)

  • #3
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by poyzn View Post
    You need to use Apache's mod_rewrite
    Add to your .htaccess file something like this
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} videos(.+)\.htm$
    RewriteRule videos-v-(.+)\.htm /videos.php?v=$1 [L,QSA]
    Thanks but seems your code is for this page "videos" only, I need to make it for all pages.
    are you know a solution for this?

  • #4
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Next code converts all .htm files into a query to index.php,
    get filename or path wiht $_GET['q']
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} (.+)\.htm$
    RewriteRule (.+)\.htm /index.php?q=$1 [L,QSA]

  • Users who have thanked poyzn for this post:

    Mido™ (01-12-2011)

  • #5
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by poyzn View Post
    Next code converts all .htm files into a query to index.php,
    get filename or path wiht $_GET['q']
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} (.+)\.htm$
    RewriteRule (.+)\.htm /index.php?q=$1 [L,QSA]
    it didn't make any thing!

  • #6
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    could you give me more details how do you what your script to work

  • Users who have thanked poyzn for this post:

    Mido™ (01-14-2011)

  • #7
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Here's a script I wrote detailing how you can do mod_rewrite. It also contains a link to a very useful tutorial: http://www.codingforums.com/showpost...40&postcount=4

    Moreover, this is a cheat sheet for explaining some of the symbols that you'll see in mod_rewrite: http://www.addedbytes.com/cheat-shee...e-cheat-sheet/

    If you have a specific problem or can't figure out something in particular please post the details and I'll do my best to assist you.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • Users who have thanked ShaneC for this post:

    Mido™ (01-14-2011)

  • #8
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by poyzn View Post
    could you give me more details how do you what your script to work
    sorry I didn't understand what's you want to ask for.

  • #9
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ShaneC View Post
    Here's a script I wrote detailing how you can do mod_rewrite. It also contains a link to a very useful tutorial: http://www.codingforums.com/showpost...40&postcount=4

    Moreover, this is a cheat sheet for explaining some of the symbols that you'll see in mod_rewrite: http://www.addedbytes.com/cheat-shee...e-cheat-sheet/

    If you have a specific problem or can't figure out something in particular please post the details and I'll do my best to assist you.
    Thanks but when I added it as you wrote in that post I got server error 500, and when I did it as that tutorial it didn't make any change!

  • #10
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    hope if any one could help me.

  • #11
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Quote Originally Posted by Mido™ View Post
    hope if any one could help me.
    You should provide a rewrite rules or rewrite patterns to make a code.
    I can't conjecture how you site's engine works.
    Please describe fully what you want

  • Users who have thanked poyzn for this post:

    Mido™ (01-17-2011)

  • #12
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by poyzn View Post
    You should provide a rewrite rules or rewrite patterns to make a code.
    I can't conjecture how you site's engine works.
    Please describe fully what you want
    I want the url to be like this :

    Code:
    http://www.domain.com/videos-v-listvideo.htm
    for all php page of the site that have variables values in url like this :

    http://www.domain.com/videos.php?v=listvideo

  • #13
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    use this code
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/([^\-]+)\-([^\-]+)\-([^\.]+)\.htm$
    RewriteRule ([^\-]+)\-([^\-]+)\-([^\.]+)\.htm$ /$1.php?$2=$3 [L,QSA]
    this code gets htm filename and split it into 3 parts.
    first - file name with the php script
    second - your variable name
    third - variable value

    if you try to load /index-get-contact.htm this code convert will convert it into query /index.php?get=contact
    Last edited by poyzn; 01-17-2011 at 09:56 PM.

  • Users who have thanked poyzn for this post:

    Mido™ (01-18-2011)

  • #14
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by poyzn View Post
    use this code
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/([^\-]+)\-([^\-]+)\-([^\.]+)\.htm$
    RewriteRule ([^\-]+)\-([^\-]+)\-([^\.]+)\.htm$ /$1.php?$2=$3 [L,QSA]
    this code gets htm filename and split it into 3 parts.
    first - file name with the php script
    second - your variable name
    third - variable value

    if you try to load /index-get-contact.htm this code convert will convert it into query /index.php?get=contact
    There is a misunderstanding here, I want to convert the php to html page, and this for the php pages with variables/values.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •