Writing htaccess rewrite rules - apache

I need help in making this htaccess rewrite rule
Suppose I have this url http://test.com/new.php?code=6789767897879&channel=1432
I need to make it http://test.com/live/6789767897879/1432.m3u8 where code and channel number are variable
So far I tried this with no luck but it keeps giving me no page found.
RewriteEngine On
RewriteBase /
RewriteRule ^/live/(.*)/(.*)?$ /new.php?code=$1&channel=$2
I am sorry but I am a beginner. Any effort is appreciated. Thanks again

Could you please try following, written and tested with your shown samples. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^live/([^/]*)/([^.]*)\.m3u8/?$ new.php?code=$1&channel=$2 [NC,L]

Related

.htaccess url parameter rewrite for specific page

I have been battling for hours now and searched Google and StackOverflow, without a solution to my problem, hope you guys can help! :-)
I have a page with parameters as follows: profile?userid=123456789. I want it to rewrite to profile/123456789. This I have, but now everywhere on this page all links gets /profile/link. Is there any fixes to this? Thanks in advance, here comes my .htaccess code.
RewriteEngine on
RewriteCond %{REQUEST_URI} !/profile\.php
RewriteRule ^profile/([^/]*)$ /profile?userid=$1 [L,QSA]
try this, it works for me with many configurations
RewriteEngine On
RewriteRule ^profile/([^/]*)$ /profile?id=$1 [L]
if you want the ([^/]*) to be exclusively number, you'll need to use PHP to rewrite your urls
You can change your rule parameter order as below to make it work
RewriteEngine on
RewriteRule ^profile?userid=([^/]*)$ profile/$1 [L]
Hope this will help you :)

assistance to with rewrite rule

I want URL to look like www.example.com/chat/91 but really the page is www.example.com/room.php?id=91 I searched online for apache rewrite example but I didn't see any examples in this format to use,
Use this RewriteRule in your .htaccess file:
RewriteEngine On
RewriteRule ^chat/([^/]*)$ /room.php?id=$1 [L]
Make sure you clear your cache before testing this.

Redirect urls with query string to seo-friendly directory like urls

I know this question is asked by many users, also I gone through many questions to find the solutions as I am unable to understand the code used in htaccess file. So please kindly help me to solve this issue. I just want to convert a link like:
www.abc.com/project.php?proj-cat=some+project+name
to url like:
www.abc.com/project/some+project+name
OR to like:
www.abc.com/project/some-project-name/
I googled and found a website which creates a htaccess rule for you, using this site I got this:
RewriteEngine on
RewriteRule project/proj-cat/(.*)/ project.php?proj-cat=$1 [L]
but this doesn't redirect to the links above.
Please help me to find the solution for this and help me understand how it works. Thank You!
You can use this code in root .htaccess:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+project\.php\?proj-cat=([^\s&]+) [NC]
RewriteRule ^ project/%1? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^project/([^/.]+)/?$ project.php?proj-cat=$1 [L,QSA,NC]
Reference: 1. Apache mod_rewrite Introduction
2. http://askapache.com

Is there a htaccess rewrite rule wildcard?

I'd like to rewrite and redirect project/issues/(some_stuff_here) to i/(same_stuff_here) . I've been fumbling around with htaccess for a while now and I haven't gotten anywhere. I'd appreciate it if someone could write out the code I need (with some helpful comments explaining why something goes where it does). Thanks! :)
EDIT: I should have mentioned that I also need i/(same_stuff_here) to display everything on project/issues/(some_stuff_here).
You can use this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^project/issues/(.*)$ /i/$1 [L,NC]

htaccess Rewrite Rule for php to png stopped working

I have created several php files that dynamically build images for user rankings. I included an htaccess file in the image directory to translate the php files into png files so that the phpBB board would allow them to be used as ranks. Up until yesterday everything was working fine. I was using the following code in the htaccess file:
RewriteEngine On
RewriteRule ^rodeojones.png$ rodeojones.php
RewriteRule ^marine.png$ marine.php
RewriteRule ^treble.png$ treble.php
RewriteRule ^major.png$ major.php
RewriteRule ^hyghway.png$ hyghway.php
RewriteRule ^zypher.png$ zypher.php
etc... Now, all of the sudden, it isn't working. I am guessing this isn't the most efficient code and therefore it is no longer working for that reason, but I am not sure. This was my first adventure in php so I am lost as to a solution. Any help would be greatly appreciated. Thank you :)
Try something like this:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteRule ^(script)/([^.]*)\.php$ $1/image.png [L]
Hopefully will help you, though needs to find more specific to your scenario !