I have 2 redirects that work fine:
Redirect 301 /namedeal/ca_domain_name.php /namedeal/cheap_domain_name.php
Redirect 301 /namedeal/ws_domain_name.php /namedeal/cheap_domain_name.php
I want to be able to replace them using regex so that any page with 2 letters followed by _domain_name.php
will be redirected.
I have tried following but not working for me. Can anyone help me get this right?
RewriteRule ^/namedeal/([a-z][a-z])_domain_name\.php$ /namedeal/cheap_domain_name.php [R=301,L]
UPDATE:
Full content of .htaccess
file which is in the sub directory namedeal
:
IndexIgnore *
ErrorDocument 400 https://www.hostfast.com/namedeal/page_missing.php?code=400
ErrorDocument 401 https://www.hostfast.com/namedeal/page_missing.php?code=401
ErrorDocument 403 https://www.hostfast.com/namedeal/page_missing.php?code=403
ErrorDocument 404 https://www.hostfast.com/namedeal/page_missing.php?code=404
ErrorDocument 500 https://www.hostfast.com/namedeal/page_missing.php?code=500
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#RewriteRule ^namedeal/[a-z]{2}_domain_name\.php$ /namedeal/cheap_domain_name.php [R=301,L]
Redirect 301 /namedeal/ca_domain_name.php /namedeal/cheap_domain_name.php
Redirect 301 /namedeal/ws_domain_name.php /namedeal/cheap_domain_name.php
Redirect 301 /namedeal/dk_domain_name.php /namedeal/cheap_domain_name.php
Redirect 301 /namedeal/bz_domain_name.php /namedeal/cheap_domain_name.php
Redirect 301 /namedeal/cn_domain_name.php /namedeal/cheap_domain_name.php
Redirect 301 /namedeal/asia_domain_name.php /namedeal/cheap_domain_name.php
#set long expiry dates for faster page loading
ExpiresActive On
ExpiresDefault A3
# Set up caching on media files for 1 month
<FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf|swf|mov|mp3|wmv|ppt)$">
ExpiresDefault A2419200
Header append Cache-Control "public"
</FilesMatch>
# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js)$">
ExpiresDefault A7200
Header append Cache-Control "private, must-revalidate"
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm|css)$">
ExpiresDefault A0
Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
Header set Pragma "no-cache"
</FilesMatch>
# Turn off Etags to speed up page loading
Header unset ETag
FileETag None
<Files 403.shtml>
order allow,deny
allow from all
</Files>
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
Ok still not working for me.
RewriteRule ^namedeal/[a-z]{2}_domain_name\.php$ /namedeal/cheap_domain_name.php [R=301,L]
#Redirect 301 /namedeal/ca_domain_name.php /namedeal/cheap_domain_name.php
The commented out line below does work.
The one with regex does not