1

My website is non www ,it has wordpress in subdirectory and some static webpages in the root and other subdirectory

  1. i want to remove .html extention from the webpages in the root and the others static webpages in subdirectory.
  2. add slash at the end.
  3. 301 redirect from non slash to url with slash.

so it should be

/articles.html to /articles/

and

/subdirectory/book.html to /subdirectory/book/

the below code

  1. working with non slash at the end
  2. redirect 301 url with slash to non

here's my .htaccess

 <IfModule mod_rewrite.c>     
 Options +FollowSymLinks -MultiViews


RewriteEngine On     
RewriteBase /

#removing trailing slash
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^(.*)/$ $1 [R=301,L]

#www to non
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?domain\.com)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]

#html
RewriteCond %{REQUEST_FILENAME} !-f     
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^([^\.]+)$ $1.html [NC,L]

#index redirect 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/     
RewriteRule ^index\.html$ http://domain.com/ [R=301,L]
RewriteCond %{THE_REQUEST} \.html     
RewriteRule ^(.*)\.html$ /$1 [R=301,L] 
</IfModule>

PS everything is ok with the wordpress , the problems with static pages only.

Thanks in advanced

1 Answers1

0

I seem not to be able to comment, it seems, but i am guessing wordpress has a separate .htaccess file that contains extra rules in order to make those pages work. I would guess your static pages will need extra explicit rules these can be added to the .htaccess or in the virtualhost but in both cases should look like: RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^staticpage1$ ./staticpage1.html RewriteRule ^staticpage2$ ./staticpage2.html

cormpadre
  • 404
  • 2
  • 5
  • yeah wordpress has a separate .htaccess –  Jul 19 '16 at 11:25
  • ok then you could try add a rule to explicitly set the redirects like: 'RewriteRule ^page$ ./page.html' – cormpadre Jul 19 '16 at 11:28
  • can you post the full code ? –  Jul 19 '16 at 11:59
  • something like: ' RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^staticpage1$ ./staticpage1.html RewriteRule ^staticpage2$ ./staticpage2.html ' – cormpadre Jul 19 '16 at 12:00
  • not working , it gives 404 –  Jul 19 '16 at 12:06
  • If you want to implement via the .htaccess (and that .htaccess is in the root) it will require full (relative to webroot) paths of the .html files rather than ./ but should work. in your example you said /subdirectory/book/ and /subdirectory/book.html in which case the redirect rule would look like "RewriteRule ^subdirectory/book$ ./subdirectory/book.html" the apache logs located in /var/log/(httpd|apache2)/ should also help identify what is being requested and give better visibility over the error. – cormpadre Jul 19 '16 at 13:16