Htaccess Rewrite

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1172 Views - Last Post: 16 February 2018 - 10:42 AM

#1 JeremyBenson11   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 274
  • Joined: 10-January 14

Htaccess Rewrite

Posted 09 February 2018 - 07:30 PM

Anyone up to help with a bit of an .htaccess rewrite? I have a pretty bad profile structure:

profile/profile.php?username=username

I need a rewrite that will turn this into a root thing:

www.domain.com/username

I also need the query string to follow after in case of pagination.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.bangsinglez.com/$1 [R,L]
RewriteRule ^(.*)$ /profile/profile.php?username=$1 [QSA]

I've tried the above but get errors, not sure if it's because I tried both or not. Are they right, or should it be something else?

Thanks,
Jeremy.

This post has been edited by JeremyBenson11: 10 February 2018 - 11:46 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Htaccess Rewrite

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6703
  • View blog
  • Posts: 31,084
  • Joined: 10-May 07

Re: Htaccess Rewrite

Posted 09 February 2018 - 07:36 PM

As rewrites are a server function, moved to Web Servers & Hosting.
Was This Post Helpful? 0
  • +
  • -

#3 JeremyBenson11   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 274
  • Joined: 10-January 14

Re: Htaccess Rewrite

Posted 09 February 2018 - 07:37 PM

Ah, thanks, and sorry about that.
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6703
  • View blog
  • Posts: 31,084
  • Joined: 10-May 07

Re: Htaccess Rewrite

Posted 09 February 2018 - 07:53 PM

No worries, I'm fumbling with Made With Love to try to resolve it now.

I have gotten rusty with the Apache re-writes having switched to nginx some time ago.
Was This Post Helpful? 0
  • +
  • -

#5 JeremyBenson11   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 274
  • Joined: 10-January 14

Re: Htaccess Rewrite

Posted 09 February 2018 - 08:05 PM

Ah, cool site for testing. Thanks man, I appreciate it. Hate having dumb urls.

^ I still haven't solved this in case anyone is confused by the above comment, lol.

Edit: I've updated the original post to have a bit more code. I was working with more that might throw someone off.

This post has been edited by JeremyBenson11: 10 February 2018 - 11:47 AM

Was This Post Helpful? 0
  • +
  • -

#6 JeremyBenson11   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 274
  • Joined: 10-January 14

Re: Htaccess Rewrite

Posted 11 February 2018 - 05:13 PM

Someone gave me this code. It works on the tester but not live. I get Internal server error 500, something like that.

RewriteEngine On
RewriteRule ^(.*)$ /profile/profile.php?username=$1 [QSA]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Was This Post Helpful? 0
  • +
  • -

#7 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2149
  • View blog
  • Posts: 6,525
  • Joined: 15-January 14

Re: Htaccess Rewrite

Posted 12 February 2018 - 10:27 AM

That means there was a web server error. Check Apache's error log.
Was This Post Helpful? 0
  • +
  • -

#8 JeremyBenson11   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 274
  • Joined: 10-January 14

Re: Htaccess Rewrite

Posted 13 February 2018 - 04:08 PM

We got a little closer, we fixed some lines of htaccess, but for some reason mp3s are not working on the new urls. The code is below.

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



You can see here that the html is the same in view source, but the songs only load and play on the long urls.

https://www.bangsinglez.com/scrimige
https://www.bangsing...ername=scrimige

Is this caused by the new htaccess lines?

This post has been edited by JeremyBenson11: 13 February 2018 - 04:10 PM

Was This Post Helpful? 0
  • +
  • -

#9 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2149
  • View blog
  • Posts: 6,525
  • Joined: 15-January 14

Re: Htaccess Rewrite

Posted 13 February 2018 - 05:01 PM

I assume that "some reason" is because Apache is applying the rewrite rules to the MP3 URLs. The most common fix is to probably add a rule that says that if the file in the URL actually exists then don't rewrite anything.
Was This Post Helpful? 0
  • +
  • -

#10 JeremyBenson11   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 274
  • Joined: 10-January 14

Re: Htaccess Rewrite

Posted 13 February 2018 - 05:19 PM

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]

This post has been edited by JeremyBenson11: 13 February 2018 - 06:46 PM

Was This Post Helpful? 0
  • +
  • -

#11 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2149
  • View blog
  • Posts: 6,525
  • Joined: 15-January 14

Re: Htaccess Rewrite

Posted 14 February 2018 - 11:04 AM

You haven't specified any conditions for that rewrite rule, so it's going to apply it to every request. If you don't want it to apply to every request then give it conditions.
Was This Post Helpful? 0
  • +
  • -

#12 JeremyBenson11   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 274
  • Joined: 10-January 14

Re: Htaccess Rewrite

Posted 14 February 2018 - 12:42 PM

Yeah, I knew when I was looking at the code what it was doing. I'm not writing the stuff, but that makes sense. I told the coder to write a condition to make sure the string after first slash does not contain another slash for a directory or a '.' for any kind of file extension.

Thanks.
Was This Post Helpful? 0
  • +
  • -

#13 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2149
  • View blog
  • Posts: 6,525
  • Joined: 15-January 14

Re: Htaccess Rewrite

Posted 14 February 2018 - 03:16 PM

Apache literally has a flag you can use to tell whether the file exists, it's built in.
Was This Post Helpful? 0
  • +
  • -

#14 JeremyBenson11   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 274
  • Joined: 10-January 14

Re: Htaccess Rewrite

Posted 15 February 2018 - 11:13 PM

I don't need it. Files are fetched from the database. All I need is .htaccess rewrite from domain/username to profile/profile.php?username=username. I gave a girl $150 dollars and that's what she gave me, a bug that re-writes every url to profile. I only picked her because she was the first to message, asked for a fair bit, and talked like she had the skills. She said she would look at it Saturday, that's if she's honest. All I know is my code was put back to some base place, whatever that means.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.bangsinglez.com/$1 [R,L]



That's what it is today.

I got this code from some guy off Reddit. It works in the tester, but not sure if it's rewriting every url. All I know is that it gives me internal errors on the server.

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


This post has been edited by JeremyBenson11: 15 February 2018 - 11:15 PM

Was This Post Helpful? 0
  • +
  • -

#15 JeremyBenson11   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 274
  • Joined: 10-January 14

Re: Htaccess Rewrite

Posted 15 February 2018 - 11:40 PM

Okay,

I wrote myself but it's erroneous. It's going to the profile url when I type:

domain/username

but it's not putting the variable/match in the query string, so I get.

domian/profile/profile.php?username=

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^[a-zA-Z0-9]+$ https://www.bangsinglez.com/profile/profile.php?username=$1 [L,QSA]


This post has been edited by JeremyBenson11: 16 February 2018 - 06:31 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2