I switched my website to wordpress but now url link end with slash(/) instead of .html and i don't wanted to lose my google index so After banging my head around here and there , I have finally found a solution. i created .htaccess rule that will work globally for every page.
I just updated the .htaccess file in root with below code:
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule ^(.*)\/$ $1.html [R]
RewriteRule ^(.*).html$ index.php/$1 [L]
Now any URL like this: /features/cart/ will automatically forward to /features/cart.html
Everything was working fine but now i am getting 404 error on those page which already have .html extension.
Please advice asap, because i am loosing my indexing and keyword ranking.
Here below is the actual code of .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.php !-f
# Rewrite rule for appending .html
RewriteRule ^(.*)\/$ $1.html [R]
RewriteRule ^(.*).html$ index.php/$1 [L]
redirect 301 /about_us.html /about.html
redirect 301 /about/ /about.html
</IfModule>
# END WordPress
Site name: dailydealbuilder.com
Try reordering your rules:
Redirect 301 /about_us.html /about.html
Redirect 301 /about/ /about.html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.php !-f
# Rewrite rule for appending .html
RewriteRule ^(.+?)/$ $1.html [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)\.html$ index.php/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Related
I followed this instruction to protect subdirectory.
https://support.hostgator.com/articles/wordpress-preventing-you-from-password-protecting-a-directory
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Changed to
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./ /index.php [L]
</IfModule>
# END WordPress
It can protect sub-directory in Wordpress without returning to 404 page but It seems that the website link is not valid.
Example. Website returns error page is it does not have slash at the end of domain.
Working domain: http://demodomain.com/something/
Not working domain: http://demodomain.com/something
try the following optionsrule just below RewriteEngine On:
1) RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]
2) #Removing trailing slash
RewriteRule ^(.*)/$ /$1 [L,R]
Add slash at the end of URL
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
Or Do Following
# Ensure all URLs have a trailing slash.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]
I created a virtualhost with MAMP. It works well when I go to example.dev. I just installed a wordpress on example.dev without any problems. When I display a page or a post, there is a /index.php which is added before the page name. For example : example.dev/index.php/pagename.
I can not access example.dev/pagename, i have a 404 error.
In permalink's options, it generates automatically /index.php/%year%/%monthnum%/%day%/%postname%/.
I selected http://example.dev/example-article/ but it is still not working.
I have a htaccess at the root
RewriteEngine On
# 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 somebody has an idea...
Thank you !!
To this url /index.php/%year%/%monthnum%/%day%/%postname%/ will work on Apache server add this rule to .htaccess file
RewriteRule ^index.php/(.*)/?$ /$1/ [L]
Above the WordPress rules:
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Given that your .htaccess have the basic WordPress rules it would look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php/(.*)/?$ /$1/ [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
END WordPress
I looked at this: htaccess remove index.php from url but it didn't work and in the comments there seems to be disagreement on the top answer.
If I type in http://www.example.com/thanksgiving/index.php/getThankyou I get the page I want served.
If I type in http://www.example.com/thanksgiving/getThankyou I get a 404.
What I've tried in my htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/thanksgiving/(.*)/$ /thanksgiving/index.php/$1 [L]
</IfModule>
How do I do it so /thanksgiving/getThankyou/ or any url starting with /thanksgiving in the url leads to the proper resource being served? Again, it is currently available when index.php is in the url.
I also tried: RewriteRule ^/thanksgiving/[^/]*/$ /thanksgiving/index.php/$1 [L] but that didn't work either...
Edit: It seemed part of the htaccess is being set by wordpress and may be conflicting with the desired behavior above:
The wordpress part of the same htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Is this interfering? How do I reconcile this with the /thanksgiving/ urls which are not part of the Wordpress application?
Edit:
The above only pertains to the root (public_html) htaccess, below is the htaccess in /thanksgiving/ itself, please analyze for conflicts, thanks for all your help!
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
# Do not change this line.
# Change example.com to your domain name
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change your_app_name to the subfolder name
RewriteCond %{REQUEST_URI} !^/thanksgiving/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change your_app_name to the subfolder name
# Change example.com to your domain name
RewriteRule ^(.*)$ /thanksgiving/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ thanksgiving/index.php [L]
You need to remove the leading slash from your rewrite pattern :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:thanksgiving/)?(.*)$ /thanksgiving/index.php/$1 [L]
</IfModule>
Otherwise the rule will accept the uri starting with a double leding slash (ie : //thanksgiving/ ) .
I want my wordpress site redirections to remember the url but place it in a subfolder.
So http://www.example.com/test123 has to redirect to http://www.example.com/voetbal/test123
And http://www.example.com/0239 to http://www.example.com/voetbal/0239
My htaccess looks like this.
RewriteEngine On
RewriteBase /voetbal/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /voetbal/index.php [R=301, L]
this makes my site go from http://www.example.com to http://www.example.com/voetbal/
but only the root.
How can i make my htaccess to remember peoples input and place it after the /voetbal/
Try :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /voetbal%{REQUEST_URI} [L,R=301]
I am converting my old site on wordpress and I don't want to loose any of the indexed "juice" as the old site has been going for 2years or so.So i have to make the same url.In my wordpress site i want to add .html at the and of my URL. I am using a plugin thats adding .html to all pages.
but its not adding .html on my product page.I want to add .html to all of my urls.
It has been suggested to us to use .htaccess rules to solve the problem, but we do not know where to start.
here is my wordpress site url.
http://www.fearfashion.com/
My full htaccess looks 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]
</IfModule>
# END WordPress
Any help would be appreciated.
You can try a rule like this to force redirect non .html URLs to .html:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.html$ [NC]
RewriteRule ^(.+?)/?$ $1.html [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress