.htaccess replace url parameter value [closed] - .htaccess

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have a URL that with some parameters. One of the parameters called 'lang' and it looks like this:
https://example.com/example1/?id=1&lang=en
I want to redirect all the current URL with lang=en to lang=gb
https://example.com/example1/?id=1&lang=gb
Note: the example1 folder is an example and it doesn't a constant variable.
every URL contains a different folder name.

This probably is what you are looking for:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(?:(.*&)?)lang=en(?:(&.*)?)$
RewriteRule ^ %{REQUEST_URI}?%1lang=gb%2 [R=301]
It is a good idea to start with a R=302 temporary redirection and only to change that to a R=301 permanent redirection once everything works as expected. That prevents nasty caching issues.
In general you should prefer to implement such rules in the actual http server's host configuration. Distributed configuration files (".htaccess") should only be used if no other alternative exist. They come with a number of disadvantages.

Related

Need to check rewrite rule [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 days ago.
Improve this question
Please can you help to correct a rewrite rule on a wordpress website.
My urls are like this one :
https://mywebsite.fr/activity/city/?location_search=city+region+country+&tax-listing_category=Activity
I want this url :
https://mywebsite.fr/activity/city/
So I need to remove everything after "activity/city/"
I tried this but not working :
RewriteRule ^([-a-z_]+)/([-a-z_]+)$ /$1/$2/^ [NC,L,QSA]
EDIT :
The urls are like this because it's wordpress pages (hierarchical structures parent-page/child-page/) and I add in the urls parameters to pre-fill the search-form in the page
You can have a look here : bit.ly/3RUybZD
If you try to remove all parameters from the url, you will see the search-form and listings updated
Thx

.htaccess RedirectMatch is OK to remove part from url? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I want to redirect this url:
domain.asd/category/node123/attachment/file123
to this one:
domain.asd/category/node123
by removing the attachment/fn1aa from the end.
Only the node123 and the file123 are dynamic.
The code below working, but it's valid, safe and resource-friendly?
RedirectMatch permanent category(.*)attachment /category/$1
Any recommendation are welcome. thx.
Try:
RedirectMatch permanent ^/category/([^/]+)/attachment /category/$1
It's more strict and won't duplicate forward slashes (/). Your regex will also match things like this:
domain.asd/foo/something/category/a/b/c/d/e/f/some-attachment
by redirecting to:
/category//a/b/c/d/e/f/some-
which probably isn't what you want to do. It's safe and as resource friendly as it is using an htaccess file (which is slight performance hit as opposed to putting this in the vhost config).

Redirection with .htaccess inside a folder [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a problem with a url a .htaccess.
I need that all url like : http://mywebsite.com/api/something go to my api/index.php cause I need to write a routing system from this place.
The .htacces must be inside the api/ folder.
What I'm trying to do here ,is a routing system who includes differents content inside the api/index.page depending on the url used.
For exemple if I go to http://mywebsite.com/api/activity I want to include a specific file without changing the url.
Do you think it's possible ? Have you an idea of the .htaccess content ?
Thanks for your help.
I've finally found the solution by myself so I post the solution, that may help another person later :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (.*) index.php [PT,QSA]
</IfModule>

Rewrite a url with htaccess [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am completely new to ht-access and I am not sure that this is the correct way to do this.
On my WordPress site, I have the current url:
http://www.example.com/category/travel/
And would like to map this to:
http://www.example.com/kids-vaction-spots/
So any post under the category travel would look like:
www.example.com/kids-vaction-spots/beach-holidays
Is it possible to have a rule in the htaccess that does this?
Thank you for taking the time to look at this.
Try adding these rules to the htaccess file in your document root. Make sure they're above any rules that do routing for a CMS.
RewriteEngine On
RewriteRule ^/?category/travel/(.*)$ /kids-vacation-spots/$1 [L,R=301]

Vanity URL But with settings [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Just a quick question,
I am making user profiles for my website and would like to include vanity URLS, but the page has a lot of separate information which gets loaded, e.g Followers tab, uploads tab, and each of these have some kind of setting that can be applied like ASC DESC, New/old results etc. What would be the best way to have vanity urls but keep the functionality i require?
http://www.site.com/user.php?id=1&content=Followers&Order=(Different settings for each result)
But i am wondering if it would be better if i should just name the content differently if someone wanted to search for followers + a limitation, for example
http://www.site.com/user.php?id=1&content=NewestFollowers,
rather than
http://www.site.com/user.php?id=1&content=Followers&Order=Newest
You typically want to construct the vanity URL so that it directly maps to query string parameters to the ugly URL. So if you have:
http://www.site.com/user.php?id=1&content=Followers&Order=Newest
You can make your vanity URL look like:
http://www.site.com/u/1/Followers/Newest/
But the /1/ bit is a little ugly, and not exactly vanity, so if you can pass a username through that query string parameter, it would look better:
http://www.site.com/u/jonlin/Followers/Newest/
Then you'd just put some mod_rewrite rules in an htaccess file in your document root that internally rewrites the vanity URL back to the ugly one:
RewriteEngine On
RewriteRule ^u/([^/]+)/([^/]+)/([^/]+)/?$ /user.php?id=$1&content=$2&Order=$3 [L,QSA]
RewriteRule ^u/([^/]+)/([^/]+)/?$ /user.php?id=$1&content=$2 [L,QSA]
RewriteRule ^u/([^/]+)/?$ /user.php?id=$1 [L,QSA]

Resources