Mod RewriteRule that matches numbers 1-15 - .htaccess

I'm using the following 3 rewrite rules to load static cached files if the user is on page 1-15. Is there a way I can combine these, particularly the last 2 into 1 rule? I've been unable to find any way to specify a range of 1-15.
RewriteRule ^$ app/webroot/cache_html/cache_static_popular_results_1.php [L]
RewriteRule ^popular/page:([1-9])$ app/webroot/cache_html/cache_static_popular_results_$1.php [L]
RewriteRule ^popular/page:(10|11|12|13|14|15)$ app/webroot/cache_html/cache_static_popular_results_$1.php [L]

Is there a way I can combine these, particularly the last 2 into 1 rule
How about
RewriteRule ^popular/page:([1-9]|1[0-5])$ app/webroot/cache_html/cache_static_popular_results_$1.php [L]

Related

.htaccess Merge 2 rules into one

I want to merge 2 rules into 1. I want to make sure cause this change will affect around 40 rules.
These are my 2 rules:
RewriteRule ^award/(\d+)/?$ admin.php?io=award&award=$1 [L]
RewriteRule ^award/add/?$ admin.php?io=award[L]
Can i merge them like this:
RewriteRule ^award/add|(\d+)/?$ admin.php?io=award&award=$1 [L]
Is this correct?
You can use:
RewriteRule ^award/(?:add|(\d+))/?$ admin.php?io=award&award=$1 [L]
With an empty parameter award for award/add.
Or:
RewriteRule ^award/(add|\d+)/?$ admin.php?io=award&award=$1 [L]
With award=add for award/add.

How to get Apache's mod_rewrite working?

I know it's been asked a hundred times, and I also took my time searching and trying. Somehow I still can't get it to work, only partially.
I have structure of urls like these: (xxxx can be numbers as well)
index.php?mode=xxxxx
index.php?category=xxx
index.php?product=xxxx
index.php?article=xxxxx
index.php?blog&post=xxxxx
The url I'd like to see in the end of all variations:
www.example.com/something
www.example.com/something/something (in the blog&post case)
I also would like to hide index.php at the end.
If only have numbers and nothing at the end, the rules would be:
RewriteEngine on
RewriteRule ^mode/([0-9]+)$ /index.php?mode=$1 [L]
RewriteRule ^category/([0-9]+)$ /index.php?category=$1 [L]
RewriteRule ^product/([0-9]+)$ /index.php?product=$1 [L]
RewriteRule ^article/([0-9]+)$ /index.php?article=$1 [L]
RewriteRule ^blog/([a-zA-Z0-9-]+)$ /blog&post=$1 [L]

rewriterule to mach "foldername" to "00_foldername"

I have 100 folders each start with a number and underscore like 001_folder1, 002_folder2.
I wrote 100 lines of rewrite code to match 001_folder1 to folder1 and etc.
RewriteRule ^/?mainFolder\/folder1\/$ mainFolder\/001_folder1/index.php [L]
RewriteRule ^/?mainFolder\/folder2\/$ mainFolder\/002_folder2/index.php [L]
.
.
I don't know if its efficient or not, but I need a general rule to match them.
something like:
RewriteRule ^/?mainFolder\/([a-z]*)$ mainFolder\/[(0-9){3}_$1 [NC,L]
Thanks
You can use this single rule to replae your 100 rules:
RewriteRule ^/?mainFolder/folder(1)/$ /mainFolder/00$1_folder$1/index.php [L,NC]

Mod Rewrite multiple parameters

I have these rules:
RewriteRule ^farbe-([^-]*)/$ ?farbe=$1 [L]
RewriteRule ^marke-([^-]*)/$ ?marke=$1 [L]
So http://playscout.de/hosen/?marke=diesel/ and http://playscout.de/hosen/?farbe=blau/ becomes http://playscout.de/hosen/marke-diesel/ and http://playscout.de/hosen/farbe-blau/
It works, but i need rules for multiple parameters like http://playscout.de/hosen/marke-diesel/farbe-blau/ so i tryed this for farbe:
RewriteRule ^farbe-([^-]*)/$ &farbe=$1 [L]
Because from second delimeter it have to be &
But it doesn't work. Any suggestions?
Put rule in top, to be executed first:
RewriteRule ^marke-([^-]*)/farbe-([^-]*)/$ ?marke=$1&farbe=$2 [L]

.htaccess 301 redirect problem

i try to redirect url's like:
example.com/video/1640/video-name
to
example.com/video/1640/video-name/
i've tried with:
RewriteRule ^video/([^/]*)/([^/]*)/$ video.php?id=$1&title=$2 [L]
RewriteRule ^video/([^/]*)/([^/]*)$ /video/([^/]*)/([^/]*)/ [R=301,L]
but it is not working
my currently htaccess file has only the first line:
RewriteRule ^video/([^/]*)/([^/]*)/$ video.php?id=$1&title=$2 [L]
and videos only loads at
example.com/video/1640/video-name/
url type
i want to redirect the non-backslash url type
example.com/video/1640/video-name
to the correct one (the one with the backslash)
How can i do this?
Your second rule should be RewriteRule ^video/([^/]*)/([^/]*)$ /video/$1/$2/ [R=301,L]
Or you could forgo the redirect totally, and just say RewriteRule ^video/([^/]*)/([^/]*)/?$ video.php?id=$1&title=$2 [L] which will allow both to view your video.
Update FallingBullets is right (see the comments on this answer), his answer better suites the OP's problem, so please ignore this answer (I am leaving it for reference, though).
Maybe you simply have to prefix your pattern with a /?? E. g.
RewriteRule ^/?video/([^/]*)/([^/]*)/$ video.php?id=$1&title=$2 [L]
RewriteRule ^/?video/([^/]*)/([^/]*)$ /video/([^/]*)/([^/]*)/ [R=301,L]
# ^ these ones
instead of
RewriteRule ^video/([^/]*)/([^/]*)/$ video.php?id=$1&title=$2 [L]
RewriteRule ^video/([^/]*)/([^/]*)$ /video/([^/]*)/([^/]*)/ [R=301,L]
since you are anchoring the pattern at the beginning of the path (using ^).

Resources