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]
Related
I'm trying to rewrite an URL with two variables by having two RewriteRule for the same page
My original URL looks like mission.php?id=var123, the first rule turn this into planning/var123 with this rule
RewriteRule ^planning/([A-Za-z0-9-\/]+)/?$ mission.php?id=$1 [NC,L]
This is a simple agenda but I want to be able to remove someone from this agenda by having an URL that should be like planning/var123/del/user so I wrote this line
RewriteRule ^planning/([A-Za-z0-9-\/]+/del/([A-Za-z0-9-\/-]+)/?$ mission.php?id=$1&del=$2 [NC,L]
I tried manually mission.php?id=var123&del=user it works, but when I'm trying to open the same page using planning/var123/del/user it does not work
I'll be glad if someone could help me
I have this url:
http://localhost/search/
This returns me this file:
http://localhost/search.html
Now I want the urls with this structure:
http://localhost/search/([^/]+)/([^/]+)/([^/]+)/?
will redirect me to the search.html file too. But without changing the url.
For example with this urls:
http://localhost/search/women/23/shoes/
http://localhost/search/
http://localhost/search/man/45/shirt/
would return the same file:
http://localhost/search.html
Note: the urls of man and women does not has any existing path in the server.
Any advice or help would be appreciated. If you need more info, let me know and I'll edit the post.
RewriteEngine on
RewriteRule ^search/ /search.html
Will just work fine. Unless you explicitly request an external redirect, a RewriteRule on the same domain will not do one, thus not changing the URL visible in the browser.
if you don't need the rest of url then you can use this
RewriteEngine On
RewriteRule ^search/(.*)$ /search.html [L]
if you need to other parameters of url then let me know
edited version, Niels Keurentjes has a point if you don't need the rest of url
RewriteEngine On
RewriteRule ^search /search.html
I need help with a URL problem I've encountered with a rewriteRule.
What I need it to do is following: example.com/en/page/page/
At the moment the following works fine: example.com/en/page/
But once it goes like "example.com/en/page/page/" I receive a 404 - page not found error even if the page in fact is located in the serverfiles.
The clue here is that I use a variable in the /en/ part of the URL (multilanguage system) and it seems that I cannot figure out how to get it to work with that included.
At the moment I have the following rewriteRule in my .htaccess file.
RewriteRule ^([^/]*)/([^/]*)/?$ index.php?lang=$1&uri=$2 [L]
Do any of you have a clue on what might work?
Best regards,
PureDarkness
You don't include anything behind the second /. You could try:
RewriteRule ^([^/]*)/(.*)$ index.php?lang=$1&uri=$2 [L]
And you can add [QSA] if you also need to get the parameters.
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 want to know how to change current URL
http://domain.com/submitticket.php
To be
http://domain.com/submit-ticket/
Let me know
RewriteRule ^submitticket/?$ /submit-ticket/
If you have no other things in you URL
RewriteRule ^submitticket/(.*)$ /submit-ticket/$1
If you have following information