Forum Moderators: phranque
# External 301 Redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,8}\ /real-file-path/real-file-name\ HTTP/
RewriteRule ^real-file-path/real-file-name$ http://www.example.com/new-file-path/new-file-name [R=301,L] # Internal Rewrite
RewriteRule ^new-file-path/new-file-name$ /real-file-path/real-file-name [L]
# External 301 Redirect to fix the problem of the real filepath being used as a URL-path
RewriteCond %{THE_REQUEST} ^[A-Z]{3,8}\ /real-file-path/real-file-name\ HTTP/
RewriteRule ^real-file-path/real-file-name$ http://www.example.com/new-URL-path-path/new-resource-name [R=301,L]
#
# Internal Rewrite to serve the correct file when the new URL is requested by the client
RewriteRule ^new-URL-path/new-resource-name$ /real-file-path/real-file-name [L]
# External 301 Redirect
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,8}\ /directory/index.php?option=com_xmap&sitemap=1&view=xml\ HTTP/
RewriteRule ^directory/index.php?option=com_xmap&sitemap=1&view=xml$ "www.mydomain.com/file.xml" [R=301,L]
# Internal Rewrite
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^file.xml$ "www.mydomain.com/directory/index.php?option=com_xmap&sitemap=1&view=xml" [L] # External 301 Redirect
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^mydomain.com$
[b]RewriteCond %{THE_REQUEST} ^[A-Z]{3,8}\ /dir/index.php\?option=com_xmap&sitemap=1&view=xml\ HTTP/
RewriteRule ^dir/index.php$ "www.mydomain.com/newfile.xml?" [R=301,L]
# Internal Rewrite
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^newfile.xml$ "www.mydomain.com/dir/index.php?option=com_xmap&sitemap=1&view=xml" [L] # External 301 Redirect
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,8}\ /dir/index.php\?option=com_xmap&sitemap=1&view=xml\ HTTP/
RewriteRule ^dir/index.php$ /newfile.xml? [R=301,L]
# Internal Rewrite
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^newfile.xml$ /dir/index.php?option=com_xmap&sitemap=1&view=xml [L]
# Externally 301 redirect requests for /dir/index/php?option=com_xmap&sitemap=1&view=xml
# in example.com domain to /newfile.xml and remove query string
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,8}\ /dir/index\.php\?option=com_xmap&sitemap=1&view=xml\ HTTP/
RewriteRule ^dir/index.php$ http://www.example.com/newfile.xml? [R=301,L]
#
# Externally redirect non-canonical example.com hostname variants to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com(\.|\.?:[0-9]+)$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# Internally rewrite requests for /newfile.xml in example.com domain back to script path
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^newfile\.xml$ /dir/index.php?option=com_xmap&sitemap=1&view=xml [L]