Need to check rewrite rule [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 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

Related

.htaccess replace url parameter value [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 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.

.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]

How can I append a string to an incoming url when someone visits the root of my website? [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 11 years ago.
Improve this question
I'm trying to get the string /index.php?page=home behind the adress in de adressbar when people visit the root of my site.
I tried rewrite rules in .htaccess but it redirects to the .php without any css etc.
Like this:
RewriteRule (.*) index.php?page=home
I tried javascript rewrite but it reloads the page
Like this:
window.location.href = "/index.html?page=home"
My page already takes the arguments and follow a javascript function, but I would like to just simply add something to the current URL in the bar, without reloading or doing anything else.
Any ideas?
By the sound of it, you'll have to use the hash to do what you want. You can go from http://example.com/#home to http://example.com/#contact without reloading the page, but you cannot go from http://example.com/index.php?page=home to http://example.com/index.php?page=contact without reloading the page.
You can set and read from the hash using window.location.hash in javascript.

Resources