Htaccess rule doesnt work - .htaccess

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_

Related

.htaccess rule is "not working"

This is my url:
http://www.mychoice.com/apppages.php?type=iphone&title=Best-Audiobooks-100&id=2617
I want to rewrite as like that:
www.mychoice.com/app/iphone/Best-Audiobooks-100/2617.html
I am using this rule for Rewrite:
RewriteRule ^app/([^/])/([^/])/([^/]*).html$ category.php?type=$1&cat=$2&catid=$3 [L]
but its not working. always redirect to 404
You forgot to add the quantifier + for first two capture groups.
RewriteRule ^app/([^/]+)/([^/]+)/([^/]+)\.html$ category.php?type=$1&cat=$2&catid=$3 [QSA,NC,L]
You have also changed the query parameter names in your substitution URL. If the target URL actually is
http://www.mychoice.com/apppages.php?type=iphone&title=Best-Audiobooks-100&id=2617
then the RewriteRule should be
RewriteRule ^app/([^/]+)/([^/]+)/([^/]+)\.html$ /apppages.php?type=$1&title=$2&id=$3 [QSA,NC,L]

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 issue, regular expression error?

i have a little problem with my .htaccess. Any suggestion?
RewriteRule vendita/([^/]+)/?$ index.php?page=1&ris_pagina=15&tipo=VENDITA&regione=$1&land=$1_vendita [L]
RewriteRule vendita/([^/]+)/pag-([^/]+)/?$ index.php?page=$2&ris_pagina=15&tipo=VENDITA&regione=$1&land=$1_vendita [L]
RewriteRule vendita/([^/]+)/([^/]+)/?$ index.php?page=1&ris_pagina=15&tipo=VENDITA&provincia=$2&land=$2_vendita [L]
RewriteRule vendita/([^/]+)/([^/]+)/pag-([^/]+)/?$ index.php?page=$3&ris_pagina=15&tipo=VENDITA&provincia=$2&land=$2_vendita [L]
RewriteRule ([^/]+)/vendita/?$ index.php?page=1&ris_pagina=15&tipo=VENDITA&comune=$1&land=$1_vendita [L]
RewriteRule ([^/]+)/vendita/pag-([^/]+)/?$ index.php?page=$2&ris_pagina=15&tipo=VENDITA&comune=$1&land=$1_vendita [L]
EXAMPLES
Url request: http://www.mysite.com/vendita/lombardia/bergamo/ ---> NOT WORKING :(
Url request: http://www.mysite.com/milano/vendita/pag-2/ ---> NOT WORKING :(
Replace the regex with ([a-z]+) for letters and ([0-9]+) for numbers it will avoid the collides between different rules.
you seem to have extraneous ? characters at the end of all your regex patterns.
vendita/([^/]+)/([^/]+)/?$
will not match
http://www.mysite.com/vendita/lombardia/bergamo
http://www.mysite.com/vendita/lombardia/bergamo?
http://www.mysite.com/vendita/lombardia/bergamo/
http://www.mysite.com/vendita/lombardia/bergamo/?a=true
it will match
http://www.mysite.com/vendita/lombardia/bergamo/?
try
^vendita/([^/]+)/([^/]+)

.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 ^).

.htacces RewriteRule problem

This is working:
RewriteRule ^([a-z]{2}/){0,1}showCategory/([0-9]*)/([0-9]*)(/{0,1})$ /main.php?id=$2&il[lang]=$1&page=$3 [L]
with this URL:
http://localhost/showCategory/590/10
Now I want to work with this too:
http://localhost/showCategory/590/transport/10
The rule I tried:
RewriteRule ^([a-z]{2}/){0,1}showCategory/([0-9]*)/([a-z\-_0-9\+]*)/([0-9]*)(/{0,1})$ /main.php?id=$2&il[lang]=$1&page=$3 [L]
How to change the RewriteRule?
This one works with both URLs
RewriteRule ^([a-z]{2}/)?showCategory/([0-9]+)(?:/[A-Za-z0-9_-]+)?/?([0-9]+)/?$ /main.php?id=$2&il[lang]=$1&page=$3 [L]
I also simplified the {0,1} with ? which does the same.
The key is in (?:/[A-Za-z0-9_-]+)?, explanation:
(?: Non-capturing group, so what's in here will not be put in any $n
/ Match the slash
[A-Za-z0-9_-]+ Match any word with letters/numbers/dashes/underscores
)? Close non-capturing group, and the ? means it's optional
Try this rule:
RewriteRule ^([a-z]{2}/)?showCategory/([0-9]+)/[a-z-_0-9+]+/([0-9]+)/?$ /main.php?id=$2&il[lang]=$1&page=$3 [L]

Resources