1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How To Add .PHP To The End Of All WordPress Pages?

Discussion in 'Blogging' started by mickyfu, May 12, 2016.

  1. mickyfu

    mickyfu Jr. VIP Jr. VIP

    Joined:
    Dec 14, 2011
    Messages:
    7,221
    Likes Received:
    20,788
    Occupation:
    King Of Crypto C
    Location:
    Solihull Young Offenders
    Hi, had to move a website over to Wordpress. Old site looked like "mywebsite/page.php. I want to replicate this on Wordpress Pages, but no the posts, and not the hompepage.
     
  2. Ste Fishkin

    Ste Fishkin BANNED BANNED Jr. VIP

    Joined:
    May 14, 2011
    Messages:
    2,058
    Likes Received:
    5,008
    Add this to your .htaccess file mickey.

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule ^(.*)$ $1.php
    
    I'm not sure if that would break anything wordpress does... I think you will be fine though.
     
    • Thanks Thanks x 1
  3. frynizy

    frynizy Registered Member

    Joined:
    Oct 3, 2013
    Messages:
    95
    Likes Received:
    28
  4. mickyfu

    mickyfu Jr. VIP Jr. VIP

    Joined:
    Dec 14, 2011
    Messages:
    7,221
    Likes Received:
    20,788
    Occupation:
    King Of Crypto C
    Location:
    Solihull Young Offenders
    This was in the htaccess file

    Code:
    # BEGIN WordPress<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    I Changed it to

    Code:
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule ^(.*)$ $1.php
    
    
    # END WordPress
    
    It made no difference.

    I want my old URLs to be able to 301 to the new URL, or the new URL to have .php at the end of the URL.

    Thanks.
     
    • Thanks Thanks x 1
  5. mickyfu

    mickyfu Jr. VIP Jr. VIP

    Joined:
    Dec 14, 2011
    Messages:
    7,221
    Likes Received:
    20,788
    Occupation:
    King Of Crypto C
    Location:
    Solihull Young Offenders
    Right so I used this plugin to get the .php on the end of the page url. But now the original URL does not work. I need both "mysite.com/page" and "mysite.com/page.php" to work.

    Now the htaccess looks like this.

    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    
    # END WordPress
    
     
  6. Sristy

    Sristy Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 17, 2010
    Messages:
    1,824
    Likes Received:
    489
    Gender:
    Female
    Location:
    In My Blog Network
    Home Page:
    And i thought adding .php to custom permalink did the job.
     
  7. rob1977

    rob1977 Power Member

    Joined:
    Mar 25, 2013
    Messages:
    775
    Likes Received:
    676
    im assuming the original was a static site rather than a cms.

    with that in mind the all else fails but longwinded depending on the site would be to get the posts into the sql database so that the original script triggers the server action. and gives you your .php because at the moment I would imagine its a static site on a worpress template and an empty database. I might be wrong.

    this would help things run smoother in the future its just a pain in the ass just now.
     
  8. SkyrocketSEO

    SkyrocketSEO Jr. VIP Jr. VIP Premium Member

    Joined:
    Nov 5, 2012
    Messages:
    4,514
    Likes Received:
    11,820
    Occupation:
    travəlɪŋ
    Location:
    Aibres
    Home Page:
    This works for posts, not pages.

    OP yo ucannot have both php and non-php pages . Also, I don't think there is a way to change ending for pages (without using mentioned plugin), just posts. I usually just solve this by deleting page and then creating a new post using same URL
     
  9. rob1977

    rob1977 Power Member

    Joined:
    Mar 25, 2013
    Messages:
    775
    Likes Received:
    676
    this is what I was getting at, its a big cut and paste job. you could speed up the process with a script
     
  10. mickyfu

    mickyfu Jr. VIP Jr. VIP

    Joined:
    Dec 14, 2011
    Messages:
    7,221
    Likes Received:
    20,788
    Occupation:
    King Of Crypto C
    Location:
    Solihull Young Offenders
    I do not want both. I just want the none .php pages to redirect to the .php pages.

    So if I type my old URL in "mysite.com/page.php" it directs to "mysite.com/page"

    or if I type my new URL in "mysite.com/page" it redirects to "mysite.com/page.php". Either way round will do.

    The old site has gone, it was created on Yola. I have no access to any of the data base or anything. I just rewritten it on Wordpress.

    A little tip to people, do not use Yola. They seem to think they can do as they please with your websites, even if not against their terms and conditions.

    More into the issue I started to remake the website a few months ago. It did not pick back up in rankings. I assume that is due to most the links being made to .php URLs, which in the standard WordPress structure is a 404. In Yola you could type in either the .php url or the url without the .php and you would land on the same page. This is what I wan with Wordpress. In Yola I made links to both .php and none .php
     
    Last edited: May 12, 2016
  11. mickyfu

    mickyfu Jr. VIP Jr. VIP

    Joined:
    Dec 14, 2011
    Messages:
    7,221
    Likes Received:
    20,788
    Occupation:
    King Of Crypto C
    Location:
    Solihull Young Offenders
    Can anyone help me with this situation. Both urls to work. One example to 301 to the other?

    Thanks. xxxxx
     
  12. dkwholesales

    dkwholesales Regular Member

    Joined:
    Feb 1, 2013
    Messages:
    320
    Likes Received:
    119
    Gender:
    Male
    Copy and paste the lines below into your .htaccess

    #MickysSecretRedirect
    Redirect 301 /page.php /page
     
    • Thanks Thanks x 2
    Last edited: May 12, 2016
  13. iBrazilian

    iBrazilian Regular Member

    Joined:
    Oct 10, 2013
    Messages:
    492
    Likes Received:
    255
    Hey, do you mean like..

    Let's say you've created a post that is a page, and not a post in the wordpress dashboard...

    http://www.example.com/make-my-site-work but it's actually a page... you just want it to add the .php to it right? Sorry, I have to ask just to be certain.
     
  14. fanatik1389

    fanatik1389 Regular Member

    Joined:
    Apr 7, 2014
    Messages:
    300
    Likes Received:
    106
    @op... So we have all .php redirecting to naked version (file.php -> file)

    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^ %1 [R,L,NC]
    </IfModule>
    # END WordPress
    
    That's all you need inside .htaccess. Tested and working for me.
     
    • Thanks Thanks x 1