rewrite {query}.m3u8 to m3u8.php?v={query} - apache

Template:
{query}.m3u8
Example:
m3u8.php?v=AAAA-000
This is what I tried:
RewriteCond %{REQUEST_FILENAME}.m3u8 -f
RewriteRule ^(.*)$ m3u8.php?v=$1

Could you please try following.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/([^.]*)\.m3u8/?$ [NC]
RewriteRule ^(.*)$ /m3u8.php?v=%1 [NC,L]
OR if you want to check if requested filename in browser is present in your system then add extra condition like:
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^/([^.]*)\.m3u8/?$ [NC]
RewriteRule ^(.*)$ /m3u8.php?v=%1 [NC,L]

Related

dynamic url change issue

I want to change my URL from https://website.com/free?s=new-check to https://website.com/free/new-check/
My Current htaccess code :
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
RewriteCond %{THE_REQUEST} /free\?s=([^\s]+) [NC]
RewriteRule ^ /%1? [NC,L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ /free?s=$1 [NC,L]
It works and directed to https://website.com/new-check but what I want is https://website.com/free/new-check/
previously I removed the .php extension from the URL.
I tried a lot of solutions but nothing works. please help me
With your shown samples, please try following htaccess Rules. Make sure to keep these Rules at top of your htaccess file if you have other Rules also in your file.
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
##https apply rules here.
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
##External redirect Rule here.
RewriteCond %{THE_REQUEST} \s/(free)\?s=([^\s]+)\s [NC]
RewriteRule ^ /%1/%2? [L,R=301]
##Internal rewrite rule here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:[^/]*)/(.*)/?$ free.php?s=$1 [NC,QSA,L]

Directing Non-Slash URL to Slash

When I enter the website.com/seo link, I want to make a 301 redirect to the website.com/seo/ link. However, I don't want it to be broken in the codes I wrote in the current htaccess.
my htacces codes:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
Based on your shown samples, could you please try following. Please clear browser cache before testing your URLs
RewriteEngine ON
RewriteBase /
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
Use only one of these, do not use together!
Try:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^\/(.*?)\/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
If that doesn't work, use:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^\/(.*?)\/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
Remove the previous rules, and try once. If it works after removing previous rules, then let me know.

How rewrite url in htaccess

Good Morning,
I have documents within the structure of my website, which are accessed with the following url format:
http://example.com/docs/files/123/mydoc.pdf
http://example.com/docs/files/475/otherdoc.pdf
I want when a url of the above type is accessed, it is renamed with the following format:
http://example.com/123/mydoc
http://example.com/475/otherdoc
I have the following rules in the htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule ^/docs/files/([0-9]+)/([a-zA-Z0-9-]+)\.([a-zA-Z-]+) /$1/$2 [QSA,L]
</IfModule>
If I type in the browser
http://example.com/docs/files/123/mydoc.pdf
It doesn't change the url to
http://example.com/123/mydoc
What am I doing wrong?
Thanks
You may try these rules in your site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+files/(\S+)\.pdf[?\s] [NC]
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/files/$1.pdf -f
RewriteRule ^(.+?)/?$ files/$1.pdf [L]
With your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s(/files/.*)\.pdf\s [NC]
RewriteRule ^ http://%{HTTP_HOST}%1 [R=301,NE]
RewriteRule ^(.*)/?$ files/$1.pdf [L]

.htaccess redirect if file exists in subfolder

I have the following challenge. Assuming the following file is requested from the server:
/pages/subfolder/mypage.php
Is there an option using mod-rewrite to do the following:
Look into a specific folder f. e. /USERMOD if the requested file (and structure) exists
If Yes, execute this file with all parameters
If Not, execute the requested file.
The background would be that the rewrite looks if there is a replacement under /USERMOD having the same folder structure. If an replacement exists use this one otherwise us the original file.
Actually (but doesn't work) I have is:
RewriteCond %{REQUEST_URI} !^/USERMOD/ [NC]
RewriteCond %{DOCUMENT_ROOT}/USERMOD/$1 -f [NC]
RewriteRule ^(.*)$ /USERMOD/$1 [L]
Thanks for any hint and help!
EDIT: The full .htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/USERMOD/ [NC]
RewriteCond %{DOCUMENT_ROOT}/USERMOD/$1 -f [NC]
RewriteRule ^(.*)$ /USERMOD/$1 [L]
RewriteCond %{REQUEST_FILENAME} ^(.*)\.(php|css|js|gif|jpg|jpeg|png)$ [NC]
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_URI} (.*)?/admin/(.*)
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_URI} (.*)?/images/(.*)
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_URI} (.*)?/templates/(.*)
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^(.+) - [L]
##boosted CONTENT
RewriteRule (.*/)?info/([A-Za-z0-9_-]+)\.html.* shop_content.php?gm_boosted_content=$2&%{QUERY_STRING} [PT,L]
##boosted PRODUCTS
RewriteRule (.*/)?([A-Za-z0-9_-]+)\.html product_info.php?gm_boosted_product=$2&%{QUERY_STRING} [PT,L]
##boosted CATEGORIES
RewriteRule (.*/)?([A-Za-z0-9_-]+)/?.* index.php?gm_boosted_category=$2&%{QUERY_STRING} [L]
Have your initial rules like this:
RewriteEngine On
RewriteRule ^USERMOD/ - [NC,L]
RewriteCond %{DOCUMENT_ROOT}/USERMOD/$1 -f [NC]
RewriteRule ^(.*)$ /USERMOD/$1 [L]
# rest of your rules come here

Add slashes and redirect pages with htacess and apache

Im trying to make it so everything with news.php in the url gets redirected to a url which strips out the news.php and adds a trailing slash. So http://www.example.com/news.php/news/article to http://www.example.com/news/article/
Ive been able to remove the news.php with this
RewriteRule ^(news|health|tips|weight|P[0-9]{2,8})$ $1/ [NC]
RewriteCond $1 ^((news|health|tips|weight|P[0-9]{2,8})/) [NC]
RewriteRule ^(.*)$ /news.php/$1 [L]
Ive tried adding a trailing slash to the above line and it does nothing.
I have also tried the stuff below, which adds a slash but doesnt remove the news.php.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /news.php/$1/ [R=301,L]
Can someone help me out here Im not sure what to do?
I also have some other rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{QUERY_STRING} ^(ACT=.*)$ [NC,OR]
RewriteCond %{QUERY_STRING} ^(URL=.*)$ [NC,OR]
RewriteCond %{QUERY_STRING} ^(CSS=.*)$ [NC]
RewriteRule ^$ /news.php\?&%{QUERY_STRING} [L]
RewriteRule ^(.*)$ $1.php [L,QSA]
RewriteCond %{HTTP_HOST} !^www2\.
RewriteRule ^(.*)$ http://www2.%{HTTP_HOST}/$1 [R=301,L]
You need an additional rule:
RewriteEngine On
RewriteCond %{THE_REQUEST} /news\.php/\S+ [NC]
RewriteRule ^news\.php/(.+?)/?$ /$1/? [R=301,L]
RewriteCond $1 ^((news|health|tips|weight|P[0-9]{2,8})/) [NC]
RewriteRule ^(.+)$ /news.php/$1 [L]
EDIT: To add a trailing slash to all non-files:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301]
Ok so I changed the first block anubhava suggested to
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
and now everything seems to be working as I want.