Mobile app version of vmapp.org
Login or Join
Michele947

: What can cause RewriteRule to work only for certain pages? Is there any extern factor (that is, not in the .htaccess file) that can cause the RewriteRule not to work for specific URLs (of

@Michele947

Posted in: #301Redirect #Htaccess

Is there any extern factor (that is, not in the .htaccess file) that can cause the RewriteRule not to work for specific URLs (of existing pages)?

I have the following code in the .htaccess (it performs redirection but not for all URLs):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php

RewriteCond %{HTTP_HOST} !^(www.)?domain.com$
RewriteRule (.*) domain.com/ [R=301,L,QSA]

</IfModule>


[Edit]
I've already made some changes since I've first posted the question, changes that didn't bring any improvement in what regards the way redirections are made - so the problem still needs a solution.
The whole .htaccess file content is:

Options +FollowSymLinks -MultiViews

RewriteEngine on




AddHandler x-httpd-php .html .htm



<ifModule mod_gzip.c>

mod_gzip_on Yes

mod_gzip_dechunk Yes

mod_gzip_item_include file .(html?|txt|css|js|php|pl)$

mod_gzip_item_include handler ^cgi-script$

mod_gzip_item_include mime ^text/.*

mod_gzip_item_include mime ^application/x-javascript.*

mod_gzip_item_exclude mime ^image/.*

mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

</ifModule>



<ifModule mod_expires.c>

ExpiresActive On

ExpiresDefault "access plus 1 seconds"

ExpiresByType text/html "access plus 1 seconds"

ExpiresByType image/gif "access plus 2592000 seconds"

ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"

ExpiresByType text/css "access plus 2592000 seconds"

ExpiresByType text/javascript "access plus 216000 seconds"

ExpiresByType application/x-javascript "access plus 216000 seconds"

</ifModule>



<ifModule mod_headers.c>

<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">

Header set Cache-Control "max-age=2592000, public"

</filesMatch>

<filesMatch ".(css)$">
Header set Cache-Control "max-age=2592000, public"

</filesMatch>

<filesMatch ".(js)$">

Header set Cache-Control "max-age=216000, private"

</filesMatch>

<filesMatch ".(xml|txt)$">

Header set Cache-Control "max-age=216000, public, must-revalidate"

</filesMatch>

<filesMatch ".(html|htm|php)$">

Header set Cache-Control "max-age=1, private, must-revalidate"

</filesMatch>

</ifModule>



<ifModule mod_headers.c>

Header unset ETag

</ifModule>


FileETag None



<ifModule mod_headers.c>

Header unset Last-Modified

</ifModule>




RewriteCond %{HTTP_HOST} !^(www.)?domain.com$
RewriteRule .? domain.com%{REQUEST_URI} [R=301,L]


#BEGIN WordPress
<IfModule mod_rewrite.c>



RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php


</IfModule>


# END WordPress

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Michele947

1 Comments

Sorted by latest first Latest Oldest Best

 

@Turnbaugh106

Old Answer

.htaccess rewrites work from the top down. Once a re-write match has been found then apache stops there. So you need to put your re-direction first like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^(www.)?domain.com$
RewriteRule (.*) domain.com/ [R=301,L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php

</IfModule>




New Answer

instead of:

RewriteCond %{HTTP_HOST} !^(www.)?domain.com$
RewriteRule .? domain.com%{REQUEST_URI} [R=301,L]


try:

RewriteCond %{HTTP_REFERER} !^http://(.+.)?domain.com/ [NC]
RewriteRule (.*) domain.com/ [R=301,L]


Or if that doesn't work try:

RewriteCond %{HTTP_REFERER} !^http://(.+.)?domain.com(.+)? [NC]
RewriteRule (.*) domain.com/ [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme