RewriteRule gives 404 - wordpress

I have troubles with mod_rewrite.
I have wordpress site located in 'wp' directory. It is accessible as http://localhost/wp/
There is page http://localhost/wp/sample-page/ on the site.
I want to make this page open with url http://localhost/wp/sample-page-2/ without redirect.
Here is what in .htaccess file:
RewriteEngine On
RewriteBase /wp/
RewriteRule ^sample-page-2/$ sample-page/ [L]
But I'm getting 404 error.
Could somebody explain me what I'm doing wrong?
Thanks in advance.
UPD:
#soju: Well, "sample-page-2" - is just example
It is not a page/post in worpress sence.
Actually I tried to add one section to the url. E.g. http://localhost/wp/sample-page/section/. And this rule RewriteRule ^sample-page/section/$ sample-page/ [L] didn't work. Then I decided to "simpliyfy" url("sample-page-2" instead of "sample-page/section") - no success.
UPD2
BTW, redirect RewriteRule ^sample-page-2/$ sample-page/ [R=301,L] works

I suppose wordpress rewrite rules are after your own rule, so you should remove [L] option to let wordpress handle sample-page url
EDIT about UPD2 : Well, it works with a 301 redirection, but you said you don't want redirection ?
You can add a filter on rewrite_rules_array to make your own rewrite rule, take a look at example on codex : http://codex.wordpress.org/Class_Reference/WP_Rewrite#Examples

Related

Override default wordpress startup

I have installed wordpress at the root (httpdocs).
When I enter domain url wordpress theme loads.
All ok, except that for now I would like that my old static index.html page is loaded instead, and that I can access wordpress with direct URI ...like /index.php
I think I need to modify .htaccess somehow for this to work? somehow I am not successfull at this. Maybe something needs to be reconfigured in wordpress as well?
I would appreciate some experts help.
Thanks!
Put something like
RewriteEngine On
RewriteRule ^$ /index.html [L]
before the Rules added by WordPress (before # BEGIN WordPress). This will match the request for / (and only that) and rewrite it to /index.html. The L flag indicates that no other rules shall be executed.
To give logged in WP users the WP site instead of your static page, use
RewriteEngine On
RewriteCond %{HTTP_COOKIE} !wordpress_logged_in
RewriteRule ^$ /index.html [L]
But why don't you just convert your static home page into the front-page for WordPress? See the documentation for more info and examples.

.htaccess subdomain languages

Im running a WordPress site with qTranslate installed.
The URLS are currently displayed as http://domain.com/en/ but i would like to change them to
http://en.domain.com
How do i make this work? qTranslate has a built-in pre-domain mode, which should do exactly what i need. But all it does is change the links (works), when visiting the page i get a 404 error.
In the admin it says "Pre-Path and Pre-Domain mode will only work with mod_rewrite/pretty permalinks. Additional Configuration is needed for Pre-Domain mode!"
I got pre-path working and i think im using pretty permalinks (/%category%/%postname%/), but ive got no idea what kind of 'additional configuration' is needed.
My .htaccess looks like this (i think standard wp output);
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I tried a lot of different things found online, but i mostly get internal server errors or just the 404.
Thanks in advance!
If your default url starts with www (like www.domain.com) then your translated urls will look like en.www.domain.com.
But if you try to login en.domain.com, you may think that your plugin doesn't working.
Before try anything be sure that any subdomains shows your WordPress homepage. With default settings WordPress should not redirect to you anywhere.
Then set your default url without www prefix (for ex. domain.com)
And check the permalink finally
If you fail at any steps, disable all plugins and even change your theme to default one.
You'd have to add wildcard domain setting at your DNS settings for the domain. https://codex.wordpress.org/Configuring_Wildcard_Subdomains‎
Wildcard domain redirect with WordPress See also this post.

Using .htaccess to redirect a domain to another URL

I have a site running wordpress, it's the full site. One of the pages is like a contact-us form located at www.ourdomain.com/contact-us/
I also have a URL like contactourdomain.com and I want it to redirect to www.ourdomain.com/contact-us/
We used to do this with a redirect on network solutions, but I prefer to have it all done right on the server if possible. I've got it sort of working but when you visit the link is still says contactourdomain.com/contact-us/ as the URL, and that breaks all the other ones.
Any suggestions?
.htaccess
Options -MultiViews
RewriteEngine on
RewriteBase /
# Rewrite
RewriteRule ^(.*)$ http://www.ourdomain.com/contact-us//$1 [L]
if you add this in .htaccess is it working?:
RewriteRule ^$ contact-us/ [R=301,L]
keep me posted..

htaccess url rewriting question

I have a site made with CodeIgniter with a WordPress site at /blog.
Say I create a page in WordPress that can be viewed at /blog/my-page.
Is it possible to rewrite the URL with .htaccess to remove the blog part of the URL? So I could enter my site url /my-page to view the page?
from the top of my head..
#start the engine
RewriteEngine on
#requests to www.yourpage.com/anything/
RewriteCond %{REQUEST_URI} ^/([^/]+)/?$ [NC]
#are sent to www.yourpage.com/blog/anything/
RewriteRule .* /blog/%1 [L]
The rule below will rewrite (internal redirect) /my-page to /blog/my-page:
RewriteEngine On
RewriteBase /
RewriteRule ^my-page$ /blog/my-page [NC,L]
RewriteRule ^another-page$ /blog/another-page [NC,L]
This needs to be placed in .htaccess in website root folder.
If you already have some rewrite rules there then this one need to be placed in appropriate place as order of rules matters.
You still may need configure WordPress a bit so it understands that this URL is for him to process (WordPress may still see the original URL). I have not worked with WordPress that much to tell if this will be required (and how to do it if it is) -- but look at Permalinks settings.

Wordpress stop post redirects

I'm having a Wordpress problem regarding permalinks.
When I have a post whose permalink is say, /2009/10/podcasts, trying to access /podcasts redirects to /2009/10/podcasts. Is there any way to stop this behavior so I can handle it as a 404?
I'm using a custom 404 handler that checks if the request is a 404 error and executes a Kohana request from within Wordpress.
I just got the answer on the WP forums. It's
remove_filter('template_redirect', 'redirect_canonical');
just checked with a default installation of wordpress - and indeed it seems to be a default behaviour of wordpress to look for the path anyways - no matter what directories you add hide. So also replacing the "/2010/01/some-long-url" by "/error/some-long-url" will redirect the reuest to "/2010/01/some-long-url".
Anyways - I can still suggest two workarounds:
1) if you really want to get a real 404 error you can use the redirect method in your htaccess to forward the request to a non-existing url - just add the one redirect-line like this:
Redirect /podcasts /podcasts-error
all together the htacces could then look like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Redirect /podcasts /podcasts-error
</IfModule>
2) If you don't really need the 404 error you may also just add a page and give it the exact same url - in this case it would be "podcasts". That would de-activate the forwarding. You could then add your own custom 'error message' to that page..
Greetz, t..

Resources