There is this regexp in htaccess:
RewriteRule ^collection/([^/_]+)games/$ some.php?coll=$1 [L]
It works fine for url's like "/collection/somegames/"
But i want the rule to accept these url's: "/collection/some-games/" to be redirected to "some.php?coll=some"
I change it to:
RewriteRule ^collection/([^/_]+)-games/$ some.php?coll=$1 [L]
or
RewriteRule ^collection/([^/_\-]+)-games/$ some.php?coll=$1 [L]
None of the above helped.
What is the solution?
RewriteRule ^collection/([^/_]+?)-?games/$ some.php?coll=$1 [L]
There you go.
Related
I want to convert this beauty of URL
http://insenti.ru/425/sayt-dlya-odinokih-ne-vybirayut/&page=2
into this
http://insenti.ru/texts.php?nead_id=425&page=2
So I use this regular expression in my htaccess:
RewriteRule insenti\.ru\/([0-9]+)\/(.*)\/(.*) insenti.ru/texts.php?nead_id=$1$3
But it has a mistake and the redirect does not work.
Here is my entire htaccess file:
ErrorDocument 404 http://insenti.ru/search/err=nopage
RewriteEngine On
RewriteRule (album|chat|help|index|landing|process_data|search|signup|sympathy|user|userspecs)/(.*) $1.php?$2
RewriteRule insenti\.ru\/([0-9]+)\/(.*)\/(.*) insenti.ru/texts.php?nead_id=$1$3
RewriteCond %{HTTP_HOST} !^insenti.ru$ [NC]
RewriteRule (.*) http://insenti\.ru/$1 [R,L]
When I check it using php preg_replace it works perfect:
$link = preg_replace('/insenti\.ru\/([0-9]+)\/(.*)\/(.*)/i', 'insenti.ru/texts.php?nead_id=$1$3', $link);
I will appreciate so much any help with that!!
RewriteRule doesn't match domain name. You can use:
RewriteEngine On
RewriteRule ^(\d+)/[^/]+/(.*)$ texts.php?nead_id=$1$2 [L,NC]
I want to change:
domain/link to domain/index.php?q=link
and
domain/notice/20151212/title-with-a to domain/index.php?q=notice&date=20151212&title=Title-with-a
with this .htaccess file:
RewriteEngine On
RewriteRule ^([a-zA-Z-]+)$ index.php?q=$1 [L]
RewriteRule ^notice/([0-9]+)/([A-Za-z0-9_-]+)$ index.php?q=notice&date=$1&title=$2 [L]
If i enter into domain/link or domain/link2, goes well but if i try to enter to domain/notice/20151212/title-with-a, I can't because it cant get CSS, image, JS files (tries to get domain/notice/20151212/js/theme.js when the file is in domain/js/theme.js) but i can enter without problems by the URL:
domain/index.php?q=notice&date=20151212&title=Title-with-a
What am I doing wrong?
I check this regex on http://htaccess.mwl.be/ and i think the htaccess file is right.
Thank you.
try to do this
RewriteEngine On
RewriteRule ^notice/([^/]+)/([^/]+)/$ index.php?q=notice&date=$1&title=$2 [L]
RewriteRule ^([a-zA-Z-]+)$ index.php?q=$1 [L]
and try to revert order like here
RewriteEngine On
RewriteRule ^notice/([0-9]+)/([A-Za-z0-9_-]+)$ index.php?q=notice&date=$1&title=$2 [L]
RewriteRule ^([a-zA-Z-]+)$ index.php?q=$1 [L]
EDIT
add [L] at the end of second line and try my url, it works
http://lab.maurosala.it/notice/a/b/
if you don't want the / at the end of url use this
RewriteRule ^notice/([^/]+)/([^/]+) notice.php?q=notice&date=$1&title=$2 [L]
I'm trying to set the first rule as optional, so both of these URLs will work:
/username
/username/history
/history
The username will never clash.
RewriteRule ^([a-z]+)/((history|analysis|messages|photos)?)$ pages/dashboard.php?username=$1&page=$2 [L]
With the above I have /username/history working. Cannot figure howto get the others.
EDIT: The above snippet is the result of trying to merge these three lines into one.
RewriteRule ^(history|analysis|messages|photos)?$ pages/dashboard.php?page=$1 [L]
RewriteRule ^([a-z]+)/(history|analysis|messages|photos)?$ pages/dashboard.php?username=$1&page=$2 [L]
RewriteRule ^([a-z]+)$ pages/dashboard.php?username=$1 [L]
You can use this rule:
RewriteRule ^(history|analysis|messages|photos)/?$ pages/dashboard.php?page=$1 [L,NC,QSA]
RewriteRule ^([a-z]+)(?:/(history|analysis|messages|photos))?/?$ pages/dashboard.php?username=$1&page=$2 [L,NC,QSA]
Trying to htaccess rewrite
old-url-part/qwerty/999-yuiop ...to...
new-url-part/yuiop-999/qwerty
RewriteRule ^old-url-part/(.*)/([0-9]+)-(.*)/?$ /new-url-part/$3-$2/$1/ [R=301,L]
The following part works fine, but struggling with the above line
RewriteRule ^old-url-part/?$ /new-url-part/ [R=301,L]
This the rule you need:
RewriteRule ^old-url-part/([^/]+)/([^/]+)/?$ new-url-part/$2/$1/ [R=301,L,NC]
I'm trying to rewrite all URL's that contain a ':' in it to another character.
http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
Example:
http://example.com/some_interesting:info
http://example.com/some_interesting_info
http://example.com/some:interesting:info
http://example.com/some:interesting_info
would all point to this file
some_interesting_info
How can I do this?
EDIT: Did more testing
this works
RewriteRule ^(.*)_(.*) $1$2 [L]
RewriteRule ^(.*)\_+(.*) $1$2 [L]
test_rewrite.html goes to testrewrite.html
this doesn't
RewriteRule ^(.*):(.*) $1$2 [L]
RewriteRule ^(.*)\:+(.*) $1$2 [L]
test:rewrite.html gives a 403
In terms of eliminating the character in the middle. Tested with xammp 1.7.1
Try these rules:
RewriteRule ^/([^:]*):([^:]*:.*) /$1_$2 [N]
RewriteRule ^/([^:]*):([^:]*)$ /$1_$2
Here's a link to RewriteRule.
RewriteRule ^/some[_:]interesting[_:]info$ /some_interesting_info [L]