I'm trying to write a rule for a date (YYYY-MM-DD)
domain.com/2017-11-17
I did some research here and I came up with this:
RewriteRule ^image-day/([0-9]{4}+-[0-9]{2}+-[0-9]{2})/?$ admin.php?do=image_day&date=$1 [L]
It seems to work, but I was wondering if there is a better or more robust way to do it.
Can i improve on my rule?
You can use:
RewriteRule ^(\d{4}-\d{2}-\d{2})/?$ admin.php?do=image_day&date=$1 [L]
And in this case, you can put the date at the root, as in your question.
Related
Hello and thanks in advance...
I have a situation where I need to completely remove the query string if it matches a pattern. I've been searching for an answer or even something close. So far, no luck. I've even tried a few things in my htaccess but without success.
The specific query string I need to remove is ?fbclid= and everything that comes after it.
Thank you!
Hard to say what your actual issue is, since you did not share your attempts so far. So we cannot help with those. All I can offer is another example. No idea if that helps.
This implements an internal rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^fbclid=
RewriteRule ^ %{REQUEST_URI} [QSD]
Here the variant for an external redirection:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^fbclid=
RewriteRule ^ %{REQUEST_URI} [QSD,R=301]
It always is a good idea to start out with a temporary 302 redirection and to only change that to a 301 once you are sure the current solution is final.
I've looked online and couldn't find exactly what I was looking. I tried to combine two different tutorials together but still nothing.
I need an .htaccess rule that changes:
game.php?id=$1&title=$2
to
/game/$1/$2.html
I've gotten it to work with one word as $2 but if there is a space, everything crashed. My current code is
RewriteEngine on
RewriteRule ^game/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ game.php?id=$1&title=$2
Any help will be greatly appreciated.
Thanks,
It looks like your wrote the opposite of what you are asking for. Currently your rewrite will rewrite
/game/$1/$2.html to game.php?id=$1&title=$2
RewriteRule ^game/([^/]+)/([^/]+)/?$ /game.php?id=$1&title=$2 [L]
if you are wanting the other way like you asked it'd look like this:
RewriteCond %{QUERY_STRING} ^id=(.*?)&title=(.*?)$
RewriteRule ^game.php$ /game/%1/%2.html? [L]
If it's only about spaces try adding "\s" to square brackets:
RewriteRule ^game/([A-Za-z0-9-\s]+)/([A-Za-z0-9-\s]+)/?$ game.php?id=$1&title=$2
I'm not going to lie. I suck at writing htaccess rules. I'm ok with regexes though.
Ok, basically, user enters url: www.site.com/page.id or www.site.com/folder/page.id
That should be internally written to: www.site.com/index.php?page=id
I've got the stuff sorted in the index.php, but I just can't seem to hack it with the htaccess.
What do you suggest it should be?
EDIT: business/legal/service-level-agreement.10 and services.5 would need to work, so the rule would need to get the digit after the dot, period.
Try this rule:
RewriteRule ^([^/]+/)?([^/]+)\.(\d+)$ index.php?$2=$3
The simplest way would be:
RewriteEngine On
RewriteRule ^([^/]*)$ index.php?page=$1 [L]
Take a look here maybe this can help:
generateit
cooletips
webmaster-toolkit
hey there, i have quite some issues with the mode rewrite here is what i use :
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]
RewriteRule ^([^/]*)/$ /creatiiuser.php?user=$1
i would like this link :
http://creatii.artcrew.ro/creatii.php?creatie_thumb=creatie19&user=dee-dee
to look:
like http://creatii.artcrew.ro/dee-dee/creatie19
well this is fine, it works, no problems with it but i want to make a rule for another link
http://creatii.artcrew.ro/categorii.php?numecat=poetry&numesubcat=satire
to look like
http://creatii.artcrew.ro/poetry/satire
how can i do this? what rules must i use?
currently if i access http://creatii.artcrew.ro/poetry/satire
it access the link : http://creatii.artcrew.ro/creatii.php?creatie_thumb=satire&user=poetry
how can i make both links(the first one and the second one) work?
one more thing, i want this link : http://creatii.artcrew.ro/creatiiuser.php?user=Dan to look like http://creatii.artcrew.ro/Dan or if that does not work http://creatii.artcrew.ro/user/Dan
how can i do that?
can anyone help me?
thanks in advance
Given the URL http://creatii.artcrew.ro/X/Y, how is mod_rewrite supposed to know whether X and Y are creatie_thumb and user values or numecat and numesubcat values?
You need to add something to the URL to differentiate these cases.
For example:
http://creatii.artcrew.ro/user/dee-dee
http://creatii.artcrew.ro/user/dee-dee/creatie19
http://creatii.artcrew.ro/cat/poetry/satire
RewriteEngine On
RewriteRule ^user/([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]
RewriteRule ^user/([^/]*)/$ /creatiiuser.php?user=$1 [L]
RewriteRule ^cat/([^/]*)/([^/]*)$ /creatii.php?numecat=$1&numesubcat=$2 [L]
Maybe you're too much generic with your rules and you got conflicts.
Try to map this urls
http://creatii.artcrew.ro/creatii/dee-dee/creatie1
http://creatii.artcrew.ro/categorii/poetry/satire
Starting from those sample you can easily map your urls with no conflict on rules
RewriteEngine On
RewriteRule ^creaati/([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]
RewriteRule ^categorii/([^/]*)/([^/]*)$ /categorii.php?numecat=$1&numesubcat=$2 [L]
Do some tries :D
I have mod_rewrite take this url:
mydomain.com/directory/index.php?slug=slug&year=2009
and make it pretty:
mydomain.com/directory/slug/2009/
Easy, but now my issue is, if someone lands at the URL without the year attached (like: mydomain.com/directory/slug/), how can I add the current year to the URL?
My current htaccess reads:
RewriteEngine on
RewriteRule ^([^/\.]+)/([^/\.]+)?$ /directory/$1/$2/ [R]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /directory/index.php?slug=$1&year=$2 [L]
Try using server variables:
RewriteRule ^([^/\.]+)/?$ /directory/$1/%{TIME_YEAR}/ [R]
If I didn't make a mistake this should redirect url:
mydomain.com/directory/slug/
to:
mydomain.com/directory/slug/2009/
(for another 2 and half months ;) )
I think you now what to do, if you don't want redirect or / at the end of url :)
I tried this in similar case, and this worked fine.
Oh, and you can find list of server variables in mod_rewrite documentation. I am not sure if this will always work.