I have some problem with WordPress.
On the news page WordPress add / in the end of URL (example: mysite.com/news.html/).
On another pages all it's okay, (example, mysite.com/page.html).
Can anyone say me how delete / on the news page?
Maybe problem with .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Maybe problem in this line: prntscr.com/1yqevq but if I change for ptk-avtom.ru/%postname%. Without /, all pages are in 404 error.
Try to add this one in your .htaccess file:
# remove trailing slash
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
Thanks
Related
I should make some url redirections (no variables to pass) in .htaccess but I don't want to let see the destination url. How can I make?
I've already tried to use Redirection instruction like this:
Redirect /en/folder1/url1 /en/folder2/url2
But in this way the destination url is visible. So I started to try to use RewriteRule like in this example:
RewriteRule ^/en/folder1/url1$ /en/folder2/url2
but I've always error page as result.
P.S. This code is inside a .htaccess file with the default Wordpress url rewrite code.
EDIT. This is the complete .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^en/folder1/url1$ en/folder2/url2
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You need to remove the leading slash from your Rule's pattern
RewriteEngine on
RewriteRule ^en/folder1/url1$ /en/folder2/url2 [L]
I have wordpress permalinks set up to /%postname% (note there is no trailing slash at the end).
However, wordpress is not redirecting any given page URL from the version with the trailing slash to the non trailing slash version. Any website header checking tool would return a '200' (OK) code for both versions (with and without the trailing slash). I am concerned this will have negative SEO consequences due to duplicate content. Therefore I want to have only one version of each page.
I am trying to modify the .htaccess file located on the wordpress directory so it removes the trailing slash at the end of any URL pretty much redirecting to the non trailing slash version of the URL.
I have Wordpress installed on a sub directory not on the root of my site i.e.
http://mywebsite.com/wordpress/
I tried the following code which I compiled by reading different questions posted on this website:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
The problem then is that I cannot login to wordpress admin. When I enter my user name and password on mywebsite.com/wordpress/wp-login.php
it typically used to redirect and enter to mywebsite.com/wordpress/wp-admin/
But now since the trailing slash is being stripped away from /wp-admin/ by the code I added to .htaccess then I get an error and cannot login to Wordpress.
I kept reading over this forums and then tried the following by playing around with the code and now I can login to wordpress but now the trailing slash is not being removed from any given URL.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/wp-admin/
RewriteCond %{REQUEST_URI} ^/wp-login\.php(.*)$
RewriteCond %{REQUEST_URI} ^/wp-admin$
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
Can anyone recommend what else I could do?
Pretty much all I want if for page URLs not to have a trailing slash at the end of the URL with the exception of the wordpress login page (mywebsite.com/wordpress/wp-login.php) and mywebsite.com/wordpress/wp-admin/
Keeping in mind the Wordpress install is on mywebsite.com/wordpress/ and not at root level.
Thanks so much!
Try these rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteRule ^((?!wp-admin/).+?)/$ /$1 [NC,NE,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
We had several domains parked on top of our main website. This was a normal HTML website and we used the following redirect so that the domain would 301 redirect to the proper url to avoid getting dinged by Google.
rewriteCond %{HTTP_HOST} ^ourmainsiteurl\.com$
rewriteRule ^.*$ http://www.ourmainsiteurl.com%{REQUEST_URI} [R=permanent,L]
So the above htaccess code just rewrites the url to www.ourmainsiteurl.com, which is what we want.
Now here's the problem... we installed Wordpress and it has the following default htaccess code:
# 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
I tried to add my redirect code in but that broke Wordpress. Can anyone tell me what I need to use to make this work?
Simply put I want all the parked domains (ie: parkedurl1.com, parkedurl2.com, etc) to be redirected to www.ourmainsiteurl.com with the htaccess file.
Make sure the redirect is before any wordpress rules:
rewriteCond %{HTTP_HOST} ^ourmainsiteurl\.com$ [NC]
rewriteRule ^.*$ http://www.ourmainsiteurl.com%{REQUEST_URI} [R=permanent,L]
# 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
If it's still not working, check to see if wordpress has something turned on that is redirecting, or adding/removing the "www" from the hostname.
I'm looking for a way to remove trailing slash for all WordPress URL's.
I found similar answers like this one but it doesn't work when there's WordPress .htaccess rules before.
Here is my current 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
It might be as simple as go to settings > permalinks in the wp admin and remove the trailing slash at the input box for custom structure
Here are the steps to remove trailing slashes site-wide. If you simply wish to remove the trailing slashes on posts only, skip to Step 2.
Important Things To Consider
In .htaccess, the code between lines # BEGIN WordPress & # END WordPress may get reset by WordPress. Avoid changing code between those lines.
Forcing removal of trailing slashes, causes a loop in example.com/wp-admin. You can avoid the issue by excluding directories RewriteCond %{REQUEST_FILENAME} !-d.
The following solution addresses those issues.
Step 1 - Update /.htaccess file
Add the following code before the # BEGIN WordPress line in your /.htaccess file. This redirects URLs with trailing slashes to URLs with no trailing slashes.
# Remove trailing slashes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
</IfModule>
Step 2 - Update Permalinks
As others have pointed out, you must also update your Permalinks (Settings -> Permalinks) to Custom Structure, and remove the trailing slash there. It removes the trailing slash on all your posts.
Try this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule (.+)/$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
If it doesn't work try this one:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule (.+)/$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
To solve this trailing slash in WordPress URL problem, log in to your website admin panel -> go to Setting Tab -> click on Permalinks under Settings. It will open a page something like the below screen:
Now, check to verify the setting you have opted for the website URL structure. Make sure that you are not leaving a trailing slash in the URL structure.
https://blog.techblogsearch.com/2018/11/29/guide-to-remove-trailing-slash-from-wordpress-url
I have uploaded a file 'events.php' to my wordpress site (the wordpress is installed in my root directory).
I would like to make a mod_rewrite to this file so that one may go to mydomain.com/events
I tried simply doing something like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule %events$ events.php [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Which didn't work.
I also found I could add rewrite tags via wordpress using its inbuilt functions like so:
add_rewrite_rule('^events?','/events.php','top');
This also didn't work - I simply end up on my default 404 page as though its reached a non-existent page within my wordpress.
What am I missing here?
Correct me if I’m wrong, but if all you want is for someone who goes to example.com/events to be directed to example.com/events.php, than you can just do a redirect like so.
Redirect 301 /events http://www.example.com/events.php
Try the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^events /events.php [L]
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The directive that you had set for the URL would not match:
RewriteRule %events$ events.php [L]
Also, the directive is now below the condition that checks for an existing file, so that it never matches a direct request for events.php.