How do you redirect a directory (in this case /resume/) to a file (/Resume.pdf) using an .htaccess file? I have tried different rewrite methods but keep getting a redirect loop. Is this because of a conflict with WordPress?
This doesn't seem to work:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^resume/ http://domain.com/Resume.pdf [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Ok, I figured it out and here's what I got to work:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/resume$ [NC]
RewriteRule ^(.*)$ http://domain.com/Resume.pdf [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Related
I have staging.namexx.my and staging2.namexx.my now.
for staging.made4u.my, it's using directoryA
And now, i want staging2.namexx.my to use directoryB to open wordpress
*staging.namexx.my is currently working, just need to let staging to use directoryA, and staging2 to use directoryB in same server.
I'm playing with the htaccess and google for some time but still cannot get it.
I need some help.
my htaccess in root
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(staging.)?namexx.my$
RewriteCond %{REQUEST_URI} !^/dicrectoryA/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dicrectoryA/$1
RewriteCond %{HTTP_HOST} ^(staging.)?namexx.my$
RewriteRule ^(/)?$ dicrectoryA/index.php [L]
</IfModule>
# END WordPress
htaccess in directoryA
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dicrectoryA/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dicrectoryA/index.php [L]
</IfModule>
# END WordPress
htacesss in directoryB
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /directoryB/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /directoryB/index.php [L]
</IfModule>
# END WordPress
Thank you!
To point staging2.namexx.my to directoryB via rewrite , you could use the following rule in your root/. htaccess .
RewriteEngine on
RewriteCond %{HTTP_HOST} ^staging2\.namexx\.my$ [NC]
RewriteRule ^ /directoryB%{REQUEST_URI} [L]
Just replace staging2.namexx.my with your real domain name and keep the rule block at the top of your htaccess.
Looking at the code, this should be working (its working for other websites/subdomains i'm working 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]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R]
</IfModule>
# END WordPress
Edit: the website is on a Redirect Loop now.
Fixed it going into Wordpress settings > General > Website URL and adding "www." to the domain :)
your redirect should be first before WordPress handles the request.
like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# 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
My website at www.tripfelt.com uses the .htaccess below to handle pretty URLs:
Options +FollowSymLinks
# enable rewrite engine
RewriteEngine On
RewriteRule ^blog - [L,NC]
RewriteRule ^robots.txt - [L]
RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_URI} !^/blog
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?/$1 [QSA,L]
www.tripfelt.com/blog uses the following .htaccess:
# 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
However, clicking on any blog item, instead of opening the blog story, is redirecting to the main site. Any ideas what I am doing wrong?
Try changing the base in your blog folder to /blog/ and remove the leading slash in the routing rule:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Solved
Blog folder
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
I need to redirect page1 to something/page1 in my wordpress site.
i have tried the below rule in my htaccess file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^page1/$ something/page1? [L]
</IfModule>
# END WordPress
i am not familiar in htaccess rules. but the redirection is not working.
can any one help me?
Thanks
Maybe this will work:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Next line added
RewriteCond %{REQUEST_URI} !page1 [NC]
RewriteRule . /index.php [L]
# Next 3 lines added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page1 something/page1? [L]
</IfModule>
# END WordPress
For permanent and visible redirection, replace [L] with [R=301,L] in the last rewrite rule.
My main domain is a Wordpress blog, and the .htaccess rewrite for it is as follows...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This works great, but I have a subdomain in that same directory, and am using this rewrite for it....
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^my\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/my/
RewriteRule ^(.*) /my/$1
That's for my wildcard SSL certificate. This works great, but if the location doesn't exist in the subdomain I get wordpress's error page. I need the wordpress rewrite to ignore the "my" subdomain. How can I do that?
I was thinking something like....
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^my\.domain\.com$
RewriteRule . /index.php [L]
</IfModule>
But that doesn't work, also tried this....
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^my\.domain\.com - [L,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Any ideas?
You should probably ignore the domain by adding a condition on the server name.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_NAME} !^my\.domain\.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Also, a thing I struggled with some time ago, try changing the htaccess of the subdomain to
RewriteBase /my
if "my" would be the directory it lives in.