RewriteRule ^groups/([0-9+]*)/(.*)$ /users.php?group=$1 [QSA,L,E]
www.mysite.com/groups/11/all-users
in users.php i try get group id:
echo $_GET['group'];
Why always get "false"?
Thanks
I heartily recommend using the RewriteLog functionality for debugging your rewrite rules, I find it helps immensely to demystify what's happening inside.
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog
From what I can tell, you're merely missing the leading slash in the URL. I tested locally using (note the added leading slash before groups):
RewriteRule ^/groups/([0-9+]*)/(.*)$ /users.php?group=$1 [QSA,L,E]
The resulting page does a vardump of $_GET, providing:
array(1) { ["group"]=> string(2) "11" }
Try with this:
Example:
The original URL: http://www.mysite.com/users.php?group=1
The rewritten URL: http://www.mysite.com/group/1
RewriteEngine On
RewriteRule ^group/([^/]*)$ /users.php?group=$1 [L]
Related
until now I have always used htaccess to rewrite URLS in order to have non-SEF url to SEF urls.
Today I am facing a new challenge that honestly, beeing non confident in regular expression, I really don't know how to achieve.
I have a situation where a forum on a website of mine has been update in the following form:
previous link: www.domain.com/forum3/topic/name-of-topic/post/7548
new link: forum.domain.com/Topic-name-of-topic/
How do I intercept /post/37764 string and tell htaccess to not consider it?
And how to instruct the server to build that kind of url instead of the provious. I am very confused about it.
Any suggestion? Thank you very much. Is there any resource that I can read to help me better understand the case?
Thanks again.
EDIT
Florian answer is correct. I just added few mods to fit it better.
RewriteEngine On
#RewriteBase /
RewriteRule ^forum3/topic/([^/]+)/post/[0-9]+$ http://forum.domanin.com/Topic-$1/ [L,R=301]
RewriteRule ^forum3/topic/([^/]+)-[0-9]+$ http://forum.domanin.com/Topic-$1/ [L,R=301]
You can try this code :
RewriteEngine On
RewriteBase /
RewriteRule ^forum3/topic/([^/]+)/post/[0-9]+$ /Topic-$1/ [L,R=301]
/([^/]+)/ means that we want to catch a string containing one or more characters except / preceded and followed by a /.
This link might help you to test your .htaccess files :
Test your apache htaccess files online
i need to remove part of Joomla/Virtuemart generated SEF URI using .htaccess
the URI represents a menu hierarchy and structured this way:
online-store
- inner-store
-product-catalog
this is the resulting URI:
www.domain.com/online-store/inner-store/product-catalog
i would like to change it to:
www.domain.com/online-store/product-catalog
thought this might help but its not making any difference
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^online-store/inner-store/\d+-(.+) /online-store/$1 [R=301,L]
i know its not considered good practice but i can't change the menu structure.
any suggestions ?
This regex \d+-(.+) will match 1 or more digits followed by hyphen followed 1 or more any thing
Try this code instead:
RewriteRule ^(online-store)/inner-store/(.*)$ /$1/$2 [R=301,L,NC]
Make sure this is first rule in your .htaccess and use a different browser to test it to avoid caching issues.
Hello I searched everywhere for a solution to this but can't find the right answer, I hope some of you can help me.
I need to change this url:
www.website.com/category/post?src=flash-game
to this one:
www.website.com/category/post?utm_source=www.referrer.com&utm_medium=swf_game_referral&utm_campaign=flash-game
So basically I need to change the "src" var to "utm_campaign" and then get the "utm_source" with "%{HTTP_REFERER}" and manually add "utm_medium" with the value "swf_game_referral"
I tried using this:
RewriteCond %{QUERY_STRING} src=(.*)
RewriteRule ^$ ?utm_source=%{HTTP_REFERER}&utm_medium=swf_game_referral&utm_campaign=%1 [QSA,R,L]
It works fine changing the GET var and adding all the other stuff but the problem is that it always redirects all the parameters to the home page, for example:
If someone goes to my website with this url:
www.website.com/category/post?src=flash-game
it will be redirected to:
www.website.com/?utm_source=www.referrer.com&utm_medium=swf_game_referral&utm_campaign=flash-game
and I need it to stay in the original path:
www.website.com/category/post?utm_source=www.referrer.com&utm_medium=swf_game_referral&utm_campaign=flash-game
You need to add the URI as part of the target, so that your RewriteRule line looks like:
RewriteRule ^(.*)$ /$1?utm_source=%{HTTP_REFERER}&utm_medium=swf_game_referral&utm_campaign=%1 [R,L]
I'm developing a multilanguage web app with Yii.
I applied changes to hide the index.php, changed urlFormat to path and added to the url path a slug with the user language example /it/index.php /en/index.php etc...
The problem now is that I need to redirect automatically to a different url once the user chooses another language. For example:
http://localhost/~antonio/project/it/women
needs to redirect to:
http://localhost/~antonio/project/it/femme
I have been playing with htaccess with no luck at all. Here is the actual code:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteBase /~antonio/project/
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
#My redirection code (tried a good few more to no use apart from this)
RewriteRule ^it/women$ it/femme
I would really appreciate any help on this issue, as it is driving me mad.
Thanks
Edit::
I surrendered with mod_rewrite. I found another solution by adding this code to /layout/main.php:
<?php
$onurl = Yii::app()->getRequest()->requestUri;
if ($onurl == "/~antonio/project/it/women") {
$this->redirect("/~antonio/project/it/femme");
} elseif ($onurl == "/~antonio/project/it/men") {
$this->redirect("/~antonio/project/it/uomme");
}
Rinse and repeat per combination of language/word
This might not work without setting up a proper Virtual Host (so that instead of local urls like http://localhost/~antonio/project/it/women you have nice urls like http://project1.dev). But I would do that anyway, since it makes your dev environment nicer! (Here's a place to start).
Anyway, I would try this: just leave the .htaccess file set like you normally would for "path" style urls, and then just parse a $_GET['lang'] parameter using the UrlManager? So you would have a urlManager setup like this in your config.php:
'urlManager'=>array(
'urlFormat'=>'path', // use path style parameters
'showScriptName'=>false, // get rid of index.php
'rules'=>array(
// this parses out the first chunk of url into the "lang" GET parameter
'<lang:[\w\-]+>/<controller:[\w\-]+>/<action:[\w\-]+>'=>'<controller>/<action>',
)
)
This way a url like this http://project1.dev/it/controller/action will redirect to the "action" action in your Controller like normal (controller/action), but in your action $_GET['lang'] will now have the value of "it".
I hope that helps, it's kind of a shot in the dark. I'm not sure how you are actually triggering the different languages, so a $_GET parameter might not be helpful after all.
Found a way to do this in htaccess:
RewriteCond %{REQUEST_URI} ^/~antonio/project/it/donna/shoes/(.*)$
RewriteRule ^it/donna/shoes/(.*)$ /~antonio/project/it/donna/calzature/$1 [L,R]
I have an old url at:
http://example.com/search/admin
I want to make it go to:
http://example.com/cgi-bin/admin
This is what I have so far, which could be completely wrong...
RewriteRule ^/search/admin$ https://example.com/cgi-bin/admin
The mod_rewrite is definitely on and working and I am using apache 2.2.
Little correction to Benubird post:
RewriteRule ^search\/admin\/?$ cgi-bin/admin [L]
RewriteRules never start with a slash and the redirect can be without slash.
the ^ character matches the start of a line ( or url in this case). Just a thought, but maybe your line should be:
RewriteRule ^/search/admin$ /cgi-bin/admin
Otherwise I suspect you'll either not be redirected, or be getting redirected to https://example.comhttps://example.com/cgi-bin/admin