-1

How would I go about having https://example.com/channels/[channel_name]/[video_id] appear in the address bar, but have my PHP script see https://example.com/channels?channel=[channel_name]&v=[video_id]? Given that [channel_name] and [video_id] would not be real directories.

  • 1
    Does this answer your question? [Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod\_Rewrite Rules but Were Afraid to Ask](https://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever) – Gerald Schneider May 16 '20 at 15:25
  • @GeraldSchneider No, it doesn't. I asked a very specific use case. If I were proficient in Mod Rewrite syntax, I wouldn't have asked. – lincolnberryiii May 18 '20 at 01:58

1 Answers1

0

I was able to find a working example of what I was looking for here:

https://www.taniarascia.com/rewrite-query-string-to-path-with-htaccess/

The code in question appears as such:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?users/(.*?)/?$ /users.php?name=$1 [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /users\.php\?name=([^\&\ ]+)
RewriteRule ^/?users\.php$ /users/%1? [L,R=301]

Where http://example.com/users/tania outputs as http://example.com/users.php?name=tania, which is the exact behavior I was looking for.

I understand the purpose of the first four lines. Could someone please elaborate on what the last two lines are for? I've tested this code over at https://htaccess.madewithlove.be/, and removing the last two lines seems to have no impact on the output.