I have been trying for several hours to modify a URL by including optional parameters
My rewriting rules do not work
It consists of an ID, a slug and the two optional parameters are "-season- {number} -" and "-episode -" {number} "
I think the problem is that the slug sometimes contains a dash at the end.
RewriteRule ^serie-([0-9]+)(-([a-z0-9/-]))? serie.php?id=$1&sl=$2 [L]
RewriteRule ^serie-([0-9]+)-([a-z0-9/-])-saison-([0-9]+)-episode-([0-9]+)$ /serie.php?id=$1&sl=$2&esid=S$3-E$4 [L]
I want this result:
serie-1-the-strain
and with optional params:
serie-1-the-strain-saison-17-episode-259
Thanks or your help!
You should update the RewriteRule as:
RewriteRule ^serie-([0-9]+)-([a-z0-9/-]+)-saison-([0-9]+)-episode-([0-9]+)$ /serie.php?id=$1&sl=$2&esid=S$3-E$4 [L]
RewriteRule ^serie-([0-9]+)(-([a-z0-9/-]+))? serie.php?id=$1&sl=$3 [L]
Related
I am new to Mod Rewrite, i just learnt a little bit so i tried to write different rules for each get parameter. Here is my full URL:
localhost/index.php?view=some-page&city=some-city&ward=some-ward&price=some-price&page=some-page
As you can see, there are 5 get parameters and the last four (city, ward, price, page) are optional. So i write different rules for each optional parameter like this:
RewriteEngine On
RewriteBase /
# No 4 optional parameter
RewriteRule ^([^/]*)/?$ index.php?view=$1 [QSA,NC,L]
# for set city parameter
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?view=$1&city=$2 [NC,L]
# for set price parameter
RewriteRule ^([^/]*)/price/([0-9]+)\.html$ /index.php?view=$1&price=$2 [NC,L]
#for set page parameter
RewriteRule ^([^/]*)/page/([0-9]+)\.html$ /index.php?view=$1&page=$2 [NC,L]
# for set city and page parameter
RewriteRule ^([^/]*)/city/([^/]*)/page/([0-9]+)\.html$ /index.php?view=$1&city=$2&page=$3 [NC,L]
# for set city, ward and page
RewriteRule ^([^/]*)/city/([^/]*)/ward/([^/]*)/page/([0-9]+)\.html$ /index.php?view=$1&city=$2&ward=$3&page=$4 [NC,L]
# all city, ward, price and page are set.
RewriteRule ^([^/]*)/city/([^/]*)/ward/([^/]*)/price/([^/]*)/page/([0-9]+)\.html$ /index.php?view=$1&city=$2&ward=$3&price=$4&page=$5 [NC,L]
This is such a headache by looking at this and i don't know whether what i did is effecient or not. So What i ask here is that: instead of writting different rule for each case, can we just write one line of Rewriterule for all like this:
RewriteRule ^([^/]*)/city/([^/]*)/ward/([^/]*)/price/([^/]*)/page/([0-9]+)\.html$ /index.php?view=$1&city=$2&ward=$3&price=$4&page=$5 [NC,L]
And telling that rule if parameter city is not set (empty), then the mapping url should be without city like this:
/index.php?view=$1&&ward=$2&price=$3&page=$4
Many thanks in advance.
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]
I want to rewrite the below:
http://www.mywebsite/address/12345/ to http://www.mywebsite/address/?param1=12345
http://www.mywebsite/address/12345/12 to http://www.mywebsite/address/?param1=12345¶m2=12
http://www.mywebsite/address/12345/?{otherparam}=1 to http://www.mywebsite/address/?param1=12345&{otherparam}=1
Below is what I have in the .htaccess file. I have the first two working fine but am struggling with the 3rd. I need the third to pass param1 and also pass other optional parameters. Can anyone assist?
RewriteRule ^address/([^/\.]+)/?$ address/?param1=$1 [NC]
RewriteRule ^address/([^/]+)/([^/\.]+)/?$ address/?param1=$1¶m2=$2 [NC]
You're looking for the QSA flag, which appends any existing query string to the newly constructed one in the rule's target:
RewriteRule ^address/([^/\.]+)/?$ address/?param1=$1 [NC,QSA,L]
RewriteRule ^address/([^/]+)/([^/\.]+)/?$ address/?param1=$1¶m2=$2 [NC,QSA,L]
Looking for some help with some pagination and mod-rewrite
okay so i've got a url that looks like this
www.website.com/page.php?phone=111-393-4949
and I'm rewriting it to look like this...
www.website.com/701-625-5444.php
with this
RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+) page.php?number=$1-$2-$3 [L,QSA]
I'm having some issues with adding my pagination to the mod rewrite now.
I am really not too sure on what all I need to do here but this is what I've come up with
RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+)/([^/]*) page.php?number=$1&page=$2 [L,QSA]
which should output..
www.website.com/494-949-9494/1.php
what is it that I'm doing wrong?
Each () pair is a capture group. Since you already have three () groups for the phone number, the ([^/]*) you added will be captured in $4.
RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+)/([^/]*)$ page.php?number=$1-$2-$3&page=$4 [L,QSA]
If the pagination is optional, add an optional non-capturing group (?:)? around the final segment:
RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+)(?:/([^/]*))?$ page.php?number=$1-$2-$3&page=$4 [L,QSA]
I will note that your RewriteRule does not forcefully include the .php as in your example www.website.com/701-625-5444.php. That would look like
RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+)\.php$ page.php?number=$1-$2-$3 [L,QSA]
# Or...
RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+)(?:/([^/]*))?\.php$ page.php?number=$1-$2-$3&page=$4 [L,QSA]
I have this rule in my htaccess:
RewriteRule ^video_(.*)$ show-video2/?txtkey=$1 [L]
Sometimes it can happend that I need another parameter in GET, for example:
.../show-video2/?txtkey=122312421&anotherparam=1232
The problem is that with this RewriteRule i'm not able too see the second parameter in $_GET:
RewriteRule ^video_(.*)$ show-video2/?txtkey=$1 [L]
How I have to modify the RewirteRule in order to see the second parameter ( when there is it )?
Infact if a var_dump($_GET) I can only see the txtkey parameter...
Change your RewriteRule to:
RewriteRule ^video_(.*)$ show-video2/?txtkey=$1 [L,QSA]
The QSA is what you're after - it means query string append - and will let you capture the rest of your GET