I need to remove trailing slash from URLs ending with .xml/ only ..
For this purpose I've created a Rewrite Condition and Rule which is working perfectly fine for the test link http://website.com/test.xml/
Test Link: http://htaccess.mwl.be?share=6fe08232-438a-53fa-8f1a-1f7f69b77b6f
The problem is when I place the rule in WordPress .htaccess file, it doesn't work at all! Seems like WordPress or YOAST Permalink structure is overriding the rule .. please help!
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} /(.*).xml/$
RewriteRule ^ /%1.xml [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Use the following code in your htacess file:
RewriteRule (.+)/$ $1 [R=301,L]
RewriteCond %{REQUEST_URI} /(.*).xml/$
RewriteRule ^ /%1.xml [L]
If not working then download new wordpress and try in that.
Related
I have modified the href link using preg_replace
for example the original link is
http://testdomain/test/save20
to
http://testdomain/save20
but when I click on this link I still get http://testdomain/test/save20
besides I only want to change it in the browser like
http://testdomain/save20
but internally it should continue to use the url
http://testdomain/test/save20
I have tried in .htaccess like this
RewriteRule ^test/([^/]+)/?$ /test=$1 [NC,L]
but it doesn't seems to have any effect.
The full code in .htaccess is like this:
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]
RewriteRule ^test/([^/]+)/?$ /test=$1 [NC,L]
</IfModule>
# END WordPress
You can use the following rule
RewriteEngine on
RewriteRule ^([^/.]+)$ /test/$1 [L]
I know there are a lot of threads for .htaccess URL rewriting, but my case seems to be a bit different and I have tried a lot but it doesn't work.
My current URL: http://example.com/forest/trees/?type=perennial
What I need is: http://example.com/forest/trees/perennial
I just need to remove the ?type= from the URL.
EDIT: The URL may contain hyphens - between strings at any point (except the domain name ofcourse). It can be dense-forest or non-perennial too.
It's a custom code and plugin, so can't modify it. I just need the URL beautified.
Any help would be greatly appreciated.
What I've tried so far in .htaccess:
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /forest\/trees\/\?type=([^&]+)
RewriteRule ^ \/forest\/trees\/%2\/? [L,R=301]
and
RewriteRule ^\/forest\/trees\/([^/]*)? /forest/trees/?type=$1 [L]
My current Wordpress .htaccess is:
# 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
Thanks in advance. :)
Cheers!
You can use this .htaccess file:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^forest/trees/([^/]+)$ /forest/trees/?type=$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Now URLs like http://example.com/forest/trees/perennial will internally redirect to /forest/trees/?type=perennial and then to Wordpress Dispatcher /index.php.
I am trying to redirect using a .htaccess file and it's not working. The syntax seems to be correct. Does any one have any ideas what is incorrect?
# 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
Redirect 301 /www.easycovertarp.com/ http://www.aeroindustries.com/products/easy-cover/
Insert this rule just below RewriteBase line:
RewriteCond %{HTTP_HOST} =local.aero.com
RewriteRule ^/?$ http://www.aeroindustries.com/products/easy-cover/ [L,R=301]
Ordering is important in mod_rewrite rules so this rule must be placed above shown WP rules.
Even after extensive research I was unable to resolve following redirection. I tried tons of examples, but with no luck.
From this URL:
http://www.example.com/store/product/name
I would like to get:
http://www.example.com/name
Problem is that the only known string is "store". Other strings "product" and "name" could contain letters, numbers and "-" or "_" characters.
I am testing it on live website and also on this tester: htaccess.madewithlove.be
One of the examples I used:
RewriteEngine On
RewriteBase /
RewriteRule ^store/([^/]+)/([^/]+) $2 [L,R=301]
This seems to work on above tester website, but not in real environment. I think there is something wrong with the regexp and second parameter is not properly returned or I am missing something else.
I should also mention that the website runs on Wordpress and in .htaccess file there is also following section created automatically by Wordpress:
# 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
Thanks for your help!
Have your rule like this i.e. redirect before internal WP rule:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^store/([^/]+)/([^/]+) $2 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I had the page name as the-book.html, but now i changed the page name to about-the-book. I have used the rewrite rule as
`Redirect 301 /the-book.html http://www.xxx.com/about-the-book.html`
but it is not working.
my full .htaccess code is here
RewriteRule ^/the-book.html$ http://www.xxx.com/about-the-book.html [R=301]
# 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
RewriteRule ^the-book.html$ http://www.example.com/about-the-book.html [R=301]
Not sure about the Redirect directive, but
RewriteRule ^the-book.html$ http://www.xxx.com/about-the-book.html [R=301]
should work nicely.
Edit:
Removed the leading / in the match part.