am trying to get this simple RewriteRule to work:
RewriteEngine On
RewriteBase /
RewriteRule ^agb$ download/AGB.pdf$ [L]
RewriteRule ^impr$ impressum$ [L]
The file exists, and I can open it, if I manually open the url.
Now I have two problems with this.
The agb rule leads to a 404
The impr rule works (funny, as it has the same syntax as the agb rule), but it doesn't mask the url, it just changes it in the browser. Shouldn't the entered url stay the same, masked, not for the user to see, that there is some other URL behind it?
Many thanks.
*edit:
After following the advice to remove the $, I started playing around with the impr rule. Seems that the rule is not making the redirects, but wordpress is. Very try from /i over /imp to /impressu leads to the /impressum site. My bad, I didn't see this.
*edit:
The full file, as requested, looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^agb$ download/AGB.pdf$ [L]
RewriteRule ^impr$ impressum$ [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Okay - when reading the comment arkascha postet AGAIN AND COMPLETELY, it really were those $ on the target path.
Thanks a lot!!!!
Related
I want to add some custom redirects on the same domain as a Wordpress installation. I want something like this:
domain.com/get/card/123456
to go to:
domain.com/account/client/redirectNewCard.php?id=123456
The same principle I want to happen to 2 other redirects, "client/validate/email/" en "enterprise/validate/email/". But none of them works.
Wordpress is saying a 404 page with "Page not found", but visiting "my domain.com/account/client/redirectNewCard.php?id=123456" DOES work and shows up what's supposed to show up.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^get/card/([0-9]+)$ /account/client/redirectNewCard.php?id=$1 [R]
RewriteRule ^client/validate/email/([0-9]+)$ /client/accountinstellingen.php?code=$1 [R]
RewriteRule ^enterprise/validate/email/([0-9]+)$ /enterprise/instellingen.php?code=$1 [R]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I already tried putting the redirect BEFORE and also AFTER the Wordpress redirects, but none of these approaches help. How can I solve this?
RewriteRule ^get/card/([0-9]+)$ /account/client/redirectNewCard.php?id=$1 [R]
RewriteRule ^client/validate/email/([0-9]+)$ /client/accountinstellingen.php?code=$1 [R]
RewriteRule ^enterprise/validate/email/([0-9]+)$ /enterprise/instellingen.php?code=$1 [R]
You need to include the L (last) flag on each of these directives. ie. [R,L].
Without the L flag, processing will continue and is likely getting rewritten by the WordPress front-controller. You need processing to stop and redirect immediately.
Greetings and thank you in advance for your help!
I am trying to redirect certain subfolders from the "category" subfolder, but not all of them. Only about 5 of them.
Example:
http://domain.com/category/fish
http://domain.com/category/lamb
Should redirect to
http://domain.com/tasty/fish
http://domain.com/tasty/lamb
But:
http://domain.com/category/lead-paint
Should not.
What I've tried (in .htaccess):
RewriteRule ^/category/fish http://example.com/tasty/fish [R=301,L]
RewriteRule ^/category/lamb http://example.com/tasty/lamb [R=301,L]
I tried both before and after the Wordpress module. I also tried inserting inside the Wordpress module like so:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/category/fish http://example.com/tasty/fish [R=301,L]
RewriteRule ^/category/lamb http://example.com/tasty/lamb [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Changes to .htaccess definately work. Typos generate a 500 response, and I can block by IP address. I'm not sure if Wordpress is overriding my redirects, or if I have a syntax error.
Thank you again.
You need to remove the leading slash just after ^ in the two rules. You also don't need to specify the full domain. The following will do
RewriteRule ^category/fish/?$ /tasty/fish [R=302,L]
(Note the 302 - always test with a temporary redirect, then change to permanent when you're happy.)
I'm trying to remove a directory from any URLS that contain it. It's a wordpress blog.
Currently the following urls 404, and probably many others:
site.com/blog/archives/yyyy/mm/dd/
site.com/blog/archives/yyyy/mm/dd/post-title/
site.com/blog/archives/author/username
However, all of these urls work fine when they are in this format:
site.com/blog/yyyy/mm/dd/
site.com/blog/yyyy/mm/dd/post-title/
site.com/blog/author/username
So pretty much I need to take any url that has the director /archive/ in it, regardless of what comes after it, and remove it. I've tried lots of example online with no luck. I feel like I must be doing something wrong and not realizing it.
The last thing I tried was this, thinking it would be a very broad rule and work. No dice.
RewriteRule (.*)/archives/(.*) $1/$2 [NC]
Here is my current .htaccess file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ([0-9]+)\.html /blog/?p=$1 [NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
Right before the # BEGIN WordPress line add:
RewriteRule ^archives/(.*)$ $1 [L,R=301]
I'm searching Google since at least 20 minutes and I can't believe it's that hard to find...
It should be pretty easy but I can't figure it out...
THE PROBLEM:
I want to put a HTML file at the same level of my Wordpress, but don't want the RewriteRules to "trap" this page and think it's a redirect...
THE HTACCESS:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# >> here << this next line is my TEST....
RewriteRule ^test\.htm$ test.htm [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Of course, a page called "test.htm" is uploaded on the server.
As stated, the line where I put my test doesn't work. It shows the WordPress homepage, instead of my "test.htm" page I uploaded.
You might try this one:
RewriteRule ^test\.htm$ - [PT,L]
It passes through (PT) the request and does not apply any further rules (L).
So, I'm trying to add my own RewriteRule in addition to what Wordpress already has. A little backgroun. The site I am working on is built off of a custom CMS, but also has a blog that is powered by WordPress. So, heres what I have thus far:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Custom rewrite for locatons
RewriteRule ^locations/(.*)$ /locations2.php?info=$1
# Wordpress rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
I also got rid of a couple lines of the Wordpress Rewrite code that seemed unecessary (everything still works....I think). But yeah, it seems like it is overwriting the rule that I wrote. Help?
Oh, also, I just tried to get rid of the . that is before /blog/index.php [L] and replaced it with just a ^, it worked...kind of. It loaded the blog when I went to /blog/, but when I went to something like /blog/author/admin, I got a 404.
I think you need to add the last flag [L] after your new rule, otherwise processing will continue and your request will be rewritten to '/blog/index.php'.
RewriteRule ^locations/(.*)$ /locations2.php?info=$1 [L]
Have you tried to remove the RewriteBase / and the slash before locations2.php ?
Something like this:
<IfModule mod_rewrite.c>
RewriteEngine On
# Custom rewrite for locatons
RewriteRule ^locations/(.*)$ locations2.php?info=$1
# Wordpress rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
If the blog gets unreacheable, move RewriteBase / to after the custom rewrite. Also, I believe that if the blog is in a sub-directory, the RewriteBase should be RewriteBase /blog/