.htaccess Merge 2 rules into one - .htaccess

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.

Related

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]

Weird rewriterule behaviour

I'm hoping someone can help me here. I'm currently trying to make my site more SEO friendly and having some strange issues with .htaccess.
This is all on my testing server. The designer section was working fine without "homeware-designer/" preceding the designer name "cquoi, etc". All good until I added the last one mage then it all stopped working, relative links were no longer working properly. I removed RewriteRule mage designerdata.php?search=4 and it all started working again. Once I added homeware-designer/etc all works fine again???? Can anyone tell me what might be going on. Also some of the rules won't work without ^foo$, but most will work without the ^$ delimiters and most will not work at all with the ^$ string delimiters. I just need to understand what is going on before I try to put it on the live server.
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteBase /
RewriteRule designer-homeware index.php
#------------------ Living ---------------
RewriteRule living-room-hallway category.php?collection=1
RewriteRule designer-shelves-storage contentdata.php?collection=1&type=17
RewriteRule designer-cushions-pouffes contentdata.php?collection=1&type=1
rewriterule designer-coat-hat-racks contentdata.php?collection=1&type=19
rewriterule designer-lighting contentdata.php?collection=1&type=25
rewriterule living-room-accessories contentdata.php?collection=1&type=4
#----------------- Eating ----------------
RewriteRule dining-room-eating category.php?collection=2
rewriterule designer-tableware contentdata.php?collection=2&type=5
rewriterule designer-glassware contentdata.php?collection=2&type=6
rewriterule dining-room-accessories contentdata.php?collection=2&type=8
#----------------- Bathing ----------------
RewriteRule ^bathroom$ category.php?collection=5
RewriteRule bathroom-accessories contentdata.php?collection=5&type=11
#----------------- Kids -------------------
RewriteRule ^childrens-decor$ category.php?collection=6
RewriteRule ^designer-childrens-decor$ contentdata.php?collection=6&type=20
#----------------- Garden ------------------
RewriteRule garden category.php?collection=7
RewriteRule garden-accessories contentdata.php?collection=7&type=21
#----------------- Art ---------------------
rewriterule designer-prints contentdata.php?collection=8&type=24
#----------------- Designers --------------
RewriteRule homeware-designers designer.php
RewriteRule homeware-designer/cquoi designerdata.php?search=7
RewriteRule homeware-designer/remember designerdata.php?search=8
RewriteRule homeware-designer/terafue designerdata.php?search=10
RewriteRule homeware-designer/r-bernier designerdata.php?search=11
RewriteRule homeware-designer/c-l-boym designerdata.php?search=21
RewriteRule homeware-designer/andre-klauser designerdata.php?search=22
RewriteRule homeware-designer/shin-azumi designerdata.php?search=23
RewriteRule homeware-designer/alejandro-ruiz designerdata.php?search=24
RewriteRule homeware-designer/tord-boontje designerdata.php?search=25
RewriteRule homeware-designer/sibo-home-concept designerdata.php?search=13
RewriteRule homeware-designer/zafferano designerdata.php?search=14
RewriteRule homeware-designer/klevering designerdata.php?search=15
RewriteRule homeware-designer/dutch-waaren designerdata.php?search=16
RewriteRule homeware-designer/vintage-casa designerdata.php?search=17
RewriteRule homeware-designer/hubsch-denmark designerdata.php?search=18
RewriteRule homeware-designer/serholt-sweden designerdata.php?search=19
RewriteRule homeware-designer/lazis designerdata.php?search=20
RewriteRule homeware-designer/atlantis designerdata.php?search=26
RewriteRule homeware-designer/mage designerdata.php?search=4
For these kind of exact-url rules, it's best to include the ^$ delimiters. The issue with needing the ^$ delimiters is that some rules are subsets of others. For example, the bathroom rule would catch the url bathroom-accessories if you didn't have the delimiters. In general, if you know that's the entire exact url you want, it's best to have the delimiters.
The other issue is these rules are all being checked, even after they match. In most cases, it isn't a problem, but like the bathroom word, some might be getting matched on more than one rule. To fix this, put [L] at the end of the rule, to indicate it's the Last rule if it matches - that is, it says if it matches, be done and exit.
It's common to also include an NC flag, for no-case, to not care if it's uppercase or lowercase.
RewriteRule designer-homeware index.php [NC,L]
#------------------ Living ---------------
RewriteRule living-room-hallway category.php?collection=1 [NC,L]
RewriteRule designer-shelves-storage contentdata.php?collection=1&type=17 [NC,L]
etc.
Try this out and see if it helps. I don't see anything wrong with the mage rule specifically, but the L and delimiters will at least keep the rules from overlapping each other.

.htaccess change /es/ to .es

I am working with a domain like:
http://www.domain.com/es/blabla.html
And I want to change the /es part for .es and convert the URLS to something like:
http://www.domain.com.es/blabla.html
I've been trying lots of possibilities but I haven't reached a solution.
For example one of them has been:
RewriteRule ^es/(.*)$ http://www.domain.com.es/$1 [L]
But it has entered in an infinite loop. Which I've tried to avoid adding this lines:
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
But the server doesn't allow this calls. So I still have the problem.
Check this.
RewriteEngine On
RewriteRule ^\.html$ /es/blabla.html [L]

Mod RewriteRule that matches numbers 1-15

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]

Resources