Page 1 of 3 123 LastLast
Results 1 to 10 of 22
  1. #1
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default mod_rewrite help +rep

    Haven't used mod_rewrite in ages.

    I have links that look like:
    site.com/index.php?p=page-name
    site.com/index.php?p=folder/page-name
    site.com/index.php?p=page-name&get=arg

    Please refresh my memory on how I would achieve:
    site.com/page-name
    site.com/folder/page-name
    site.com/page-name/get/arg

    Thanks!
    Vouches
    [x][x]

  2. #2
    Join Date
    Jun 2012
    Posts
    47
    Tokens
    0

    Default

    Hi Fazon.

    Are you looking for something like this?


    Code:
    RewriteRule ^page-name/([^/]+)(|/)$ /index.php?p=$1
    That is only an example for the first one.

  3. #3
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    Yeah that's what I'm looking for!

    Is there a way to make it so that it ignores the /site-name/? For example:

    google.com/index.php?p=register becomes google.com/register

    Thanks again.

    QUOTE=Nath.;7572053]Hi Fazon.

    Are you looking for something like this?


    Code:
    RewriteRule ^page-name/([^/]+)(|/)$ /index.php?p=$1
    That is only an example for the first one.[/QUOTE]
    Vouches
    [x][x]

  4. #4
    Join Date
    Jun 2012
    Posts
    47
    Tokens
    0

    Default

    Code:
    RewriteRule ^page-name/(|/)$ /index.php?p=$1
    That should work.

  5. #5
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    Quote Originally Posted by Nath. View Post
    Code:
    RewriteRule ^page-name/(|/)$ /index.php?p=$1
    That should work.
    Nope, doesn't seem to work.
    Vouches
    [x][x]

  6. #6
    Join Date
    Jun 2012
    Posts
    47
    Tokens
    0

    Default

    Hi Fazon,

    Can you give me an example of the URL and what the URL actually looks like? (You don't need to give me your website URL).

  7. #7
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    (Actual URLs)

    Using the latest code you provided:

    www.hab.net63.net/index.php?p=register doesn't become www.hab.net63.net/register/

    When I tried the first code, that same link above became www.hab.net63.net/site-name/register
    Vouches
    [x][x]

  8. #8
    Join Date
    Jun 2012
    Posts
    47
    Tokens
    0

    Default

    Code:
    RewriteEngine on
    RewriteRule ^register(|/)$ index.php?p=register
    It won't change the page name, but instead of redirecting a user (with a link or whatever) to www.hab.net63/index.php?p=register you can direct them to: www.hab.net63/register.

    Hope I helped.

  9. #9
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    Quote Originally Posted by Nath. View Post
    Code:
    RewriteEngine on
    RewriteRule ^register(|/)$ index.php?p=register
    It won't change the page name, but instead of redirecting a user (with a link or whatever) to www.hab.net63/index.php?p=register you can direct them to: www.hab.net63/register.

    Hope I helped.
    But how can I make it apply globally to all pages? If I'm not mistaken, that will only apply to index.php?p=register. What if I have register, login, logout (for example)?
    Vouches
    [x][x]

  10. #10
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    I believe you can use a wildcard like so:
    Code:
    RewriteEngine On
    RewriteRule ^(.*)$ index.php?title=$1 [PT,L,QSA]
    Last edited by Chippiewill; 18-06-2012 at 07:32 PM.
    Chippiewill.


Page 1 of 3 123 LastLast

Posting Permissions

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