1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Htaccess Rewrite

Discussion in 'Apache' started by Jeremy Benson, Feb 10, 2018.

  1. #1
    Hello,
    SEMrush
    I'm having trouble with htaccess. I'd like to re-write a long url to short one, while allowing for pagination.

    https://www.mydomain.com/profile/profile.php?username=username
    to
    https://www.mydomain.com/username

    However, the first url could be.
    https://www.mydomain.com/profile/profile.php?username=username&page=1

    I've got a couple lines that I tried, but neither work, and I'm not sure if they're on the right track. They're just snippets I found while Googling. Any help getting this right would be greatly appreciated.

    
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.bangsinglez.com/$1 [R,L]
    RewriteRule ^(.*)$ /profile/profile.php?username=$1 [QSA]
    
    Code (markup):
     
    Last edited: Feb 10, 2018
    Jeremy Benson, Feb 10, 2018 IP
    SEMrush
  2. hostechsupport

    hostechsupport Active Member

    Messages:
    156
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    88
    #2
    If you have cPanel, you can set redirection.
     
    hostechsupport, Feb 12, 2018 IP
  3. voon

    voon Active Member

    Messages:
    23
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    63
    #3
    May be replace [QSA] flag with %{QUERY_STRING} would help?

    
    RewriteRule ^(.*)$ /profile/profile.php?username=$1&%{QUERY_STRING}
    
    Code (markup):
     
    voon, Feb 12, 2018 IP
  4. Jeremy Benson

    Jeremy Benson Active Member

    Messages:
    337
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    73
    #4
    Wait, the issue has been half fixed. It causes an issue though. Mp3s will not play on the new urls. There are no files in the url though, they're fetched from the database with php and the urls are created in html. I have no idea why the mp3s won't play. I'll show the new htaccess code.

    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteRule ^([^/]*)$ profile/profile.php?username=$1 [L,QSA] 
    Code (markup):
    If you view source on the two pages you will see the url paths to the mp3s are identical. Not sure what's causing the problem.

    http://www.bangsinglez.com/scrimige
    http://www.bangsinglez.com/profile/profile.php?username=scrimige
    Code (markup):
     
    Jeremy Benson, Feb 13, 2018 IP
  5. Jeremy Benson

    Jeremy Benson Active Member

    Messages:
    337
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    73
    #5
    I've fixed this issue, but the site was rewriting everything to profile and I was getting my "profile not found error." as if the username value wasn't present or didn't hold a chosen username. Can you tell by the code here what is causing that, or if it's writing everything to profile.php and why?

    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteRule ^([^/]*)$ profile/profile.php?username=$1 [L,QSA]
    Code (markup):
     
    Jeremy Benson, Feb 13, 2018 IP