htaccess query string /? - wordpress

I've been searching similar examples but I was not able to find the answer in WordPress.
In google analytics I can see various string types for the same url's coming in. I looked at the htaccess file and deactivated the cache system but it's still occurring. Not sure why yet.
Now in htaccess I would like to redirect all those url's to the correct one:
Example:
// CORRECT: ...domain.com/everest-nepal/
// INCORRECT 1: ...domain.com/everest-nepal/?/
// INCORRECT 2: ...domain.com/everest-nepal/?/=
// CORRECT 3: ...domain.com/everest-nepal/?amp (this is amp related and not interested in redirecting it to the canonical url)
Is there a possible rewrite condition that could be applied in htaccess to redirect all these url's coming with this strange /?* at the end avoiding the amp?
Thanks and regards
Enric

Once you update permalinks in wordpress admin you will get .htaccess code below like this, You need to create .htaccess file in your root folder, and paste this below code, this should work,
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Related

how to redirect from htaccess /en/blog to a folder located at ./blog

I have a store in pretashop 1.6 with url www.example.com/en/ in the root of the project I have a folder called blog that contains a wordpress, to view the blog, the url is as follows www.example.com/blog/, I need it to be www.example.com/en/blog/
I have tried the following:
Put the blog in a folder ./en/blog, from htaccess add the 301 redirect from /blog to /en/blog, I have changed in the wordpress database the references from */blog to */en/blog and it works correctly, but the prestashop store does not work, since when entering www.example.com/en throws an access denied error.
I think what I need to do with htaccess is that when I search for /en/blog/ the folder I read is /blog even if the url shows /en/blog/, but I can't know how to do it.
How can I do it? Can you think of an idea?
Thank you very much for your answers
based on this documentation
I put an example of how I think the .htaccess can work, also refresh the permanent links in WordPress and save again.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /en/blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /en/blog/index.php [L]
</IfModule>
#END WordPress

Wordpress Problematic URL

I have a custom page in wordpress that uses a custom plugin which is connecting to an API to retrieve information.
The client has asked that we don't pass id's via the url as below:
http://beta.hirehere.co.uk/hire-vehicle-detail/?id=4
but instead use a category name such as:
http://beta.hirehere.co.uk/hire-vehicle-detail/?vehicle_category_name=economy
initially I was using a URL rewrite to pretty things up so:
http://beta.hirehere.co.uk/hire-vehicle-detail/4
and thought I would just change it to:
http://beta.hirehere.co.uk/hire-vehicle-detail/economy
I would then adjust the code accordingly. I've done this yet the URL rewrite does not seem to be happy and returns a 404 error but it works if I access the direct url of:
http://beta.hirehere.co.uk/hire-vehicle-detail/?vehicle_category_name=economy
Here is my htaccess file, any help is greatly appreciated:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^hire-vehicle-detail/(.+)$ index.php/hire-vehicle-detail?vehicle_category_name=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
PS. The above htaccess code worked in the scenario of using ID's instead
Edit: it appears wordpress is trying to access a sub-page (economy) of the parent page (hire-vehicle-detail). I know this because if I create the page economy as a child of hire-vehicle-detail the url takes me there. Is there anyway to stop this

Change permalinks from post id to post name in Wordpress without using a plug in or getting error 404

I have a wordpress site and i want to change the permalink structure from post id to post name. I already have 100 posts and do not want to break the old links so i want to redirect them without getting error 404. The thing is i know there are plug ins to do the job for you but i prefer to not use plug ins in my website when i can avoid them! Is there a way to do the whole redirect old links without using a plug in? I read something about editing the htaccess file but I couln't pull it off! thanks in advance
Use on this code into your root .htaccess file than permalink change to post name. & collect your old post url than use 301 redirect plugin.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
or you can help with this site.
https://www.themeconfig.com/wordpress-basic-services/
thank you

Clean up an htaccess from infections

I have a simple wordpress website and it seems to be hacked. I used some plugins to scan it and they say my htaccess file is infected. Now I could use some help clean it up - specifically, to understand
What to look for to clean up? I.e. what does an "infection" in htaccess look like?
how can I prevent unauthorized access to the file in the future?
The htaccess in question is:
http://pastebin.com/TcWiQvNP
Here's default wordpress htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
also for permission
set chmd to 644
First, you need basic understanding of mod_rewrite configuration structure to understand what your current file does and be able to edit it correctly.
Now, the broadly defined redirects to some absolute URLs do look suspicious. But I don't know if the URLs correspond to your site or some other.
In general, you need to identify which directives are "alien" - i.e. do not correspond to the apps you're running at the server.

Using mod_rewrite for GET variables in a Wordpress blog page

I am working on a wordpress blog, with the default .htaccess settings:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
In my wordpress blog, I have created a page called "mypage". Using my rewrite settings, it is shown in the address bar as http://www.mysite.com/mypage.
I am using a custom page template and am processing some things, which include the use of GET variables. For instance:
if (isset($_GET='word')) { echo $_GET['word]; }
So, http://www.mysite.com/mypage?word=dog will display "dog".
The problem I am having is rewriting the URL so that it can look like: http://www.mysite.com/mypage/dog, still being able to access "dog" as the GET variable.
I am not too good with mod_rewrite rules to begin with, but working from within a wordpress installation is throwing me an extra curveball.
Does anyone know what I need to add to my .htaccess to achieve this?
Thank you!
Try the following:
RewriteRule ^mypage/([^/])/?$ mypage?word=$1 [L,QSA]
The L flag instructs .htaccess to stop processing rules, and QSA appends the query string since you might have other GET parameters on the end of the URL.
Mod_Rewrite Documentation

Resources