SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    Founder of Primal Skill Ltd. feketegy's Avatar
    Join Date
    Aug 2006
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Help me out with PHP links

    Hello,
    If somebody please help me out to make my links friendly

    currently I have index.php?page=1&id=10 style links

    and i want to rewrite it to a nice page/company/1 (this is just an example) style links

    BUT i'd like not to rewrite all the links in the PHP script

    Is this possible?

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sure.

    Look up .htaccess's MOD_REWRITE. You can use REGEX to grab page/company/1 to index.php?page=page&company=company&id=1
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    Founder of Primal Skill Ltd. feketegy's Avatar
    Join Date
    Aug 2006
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I know this. But then I have to change the links in th PHP script to page/company/1 style links

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, what I would do is create a PHP script which goes through all of your PHP files (using fopen), and use REGEX to search for the urls to be changed, and change them into the urls you want in the end.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Addict
    Join Date
    Aug 2007
    Location
    GR
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We use for example a virtual host site where it is physically located in /usr/home/username/public_html

    <Directory "/usr/home/username/public_html">
    Options +FollowSymLinks
    Override None
    Order allow,deny
    Allow from all
    RewriteEngine On
    RewriteBase /
    RewriteRule ^([0-9]+)/company/([0-9]+)$ index.php?page=$1&id=$2 [QSA,L]
    </Directory>

    If you are using an .htaccess file, just drop some of the lines in it:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^([0-9]+)/company/([0-9]+)$ index.php?page=$1&id=$2 [QSA,L]


Bookmarks

Posting Permissions

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