Mod Rewrite multiple parameters - .htaccess

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]

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.

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]

.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]

Htaccess rule doesnt work

I have got this rule.. which I put as my first rule
RewriteRule ^categories_compare/$ index.php?app_table_comparison=3 [L]
This is the url that I type:
http://apps.com/categories_compare
The problem is that it doesnt do the redirect.. why is that?
This is part of my htaccess:
RewriteRule ^news2/([^/\.]+).(html)$ index.php?news_url_two=$1 [L]
RewriteRule ^news/([^/\.]+).(html)$ index.php?news_url=$1 [L]
RewriteRule ^categories_compare/?$ index.php?app_table_comparison=3 [L]
I want the last rule to work.
Your regular expression is: ^news3/$, so it wants a trailing / at the end but you're only going to news3. Try changing your rule to:
RewriteRule ^news3/?$ index.php?app_table_comparison=3 [L]
The /? means the slash is optional.
RewriteRule categories_compare http://fuckedapps.com/index.php?app_table_comparison=3 [L]
Okay that is the solution without any ^ or / or ^ or $.
Weird thing that it didnt work when I put ^categories_

.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