I want to redirect domainA.com/folder/ which originates within an older wordpress installtion to domainB.com/folder1/folder2/ which is the link to the page within my new wordpress installation wihtout the url changing.
I have managed to achieve this with the .htaccess file inside domainA.com/folder/ which reads:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/folder
RewriteRule ^(.*)$ http://www.domainB.com/folder1/folder2/ [P]
The Rewriterule [P] (proxy) flag does what I want and redirects the page without changing the url but some of the content within my Enfold WP template such as the advanced layer slider and icons fail to load.
I assume this error is due to some sort of conflict with WP's native htaccess code and I also suspect it has to do with the lines:
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I have experimented with adding the first, third and fourth lines to my code but it doesnt work. Does anybody know how I could resolve this issue?
If it makes any difference the wordpress site I want to direct to (domainB.com/folder1/folder2/) is one whithin a Wordpress Network.
For the moment I have changed the [P] flag to [L] flag which redirects and works but changes the url.
Any help or advice would be much appreciated. Thank you!
Try to change the paths of images (the URLs) in advanced layer slider and icons URLs from
relative to absolute ones (as described in RFC 2396), then you can use the [P] flag in .htaccess again.
Often plugins uses relative paths when outputting content, but this can cause such type of troubles.
This following code takes care of permalinks in WorPress and it is recommended to keep the beginning and ending WordPress lines so that WordPress is able to locate it and modify it as needed. You may already have all this and are just not displaying it. I do not know.
# 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
In the other section you probably need to remove the trailing / after folder2 like so:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/folder
RewriteRule ^(.*)$ http://www.domainB.com/folder1/folder2 [P]
Related
I am trying to make a URL go to a file which is a WordPress page template.
I am doing a website that has categories and subcategories then a details page.
First off I am try to make.
www.example.com/explore/category_name
The category_name is dynamic and pulled from a non WordPress database.
I am trying to get that any time the URL is www.example.com/explore/whatever. It points to /wp-content/themes/my_theme/myfile.php
Here is my .htaccess file.
RewriteEngine On
RewriteBase /
RewriteRule ^explore/([a-z0-9-]+)$ /wp-
content/themes/visitsi_theme/listing-page.php [NC]
#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
RewriteRule ^explore/([a-z0-9-]+)$ /wp-
content/themes/visitsi_theme/listing-page.php [NC]
You need to include the L flag to prevent the WP directives that follow being processed. I would also remove NC flag and make the "whatever" match A-Z if required. Otherwise, /ExPlOrE/ would be accepted (rather than generating a 404). This directive is also split across two lines (in the middle of the substitution) - although maybe that's a typo? (But it certainly needs fixing.)
So, try the following instead:
RewriteRule ^explore/([a-zA-Z0-9-]+)$ /wp-content/themes/visitsi_theme/listing-page.php [L]
visitsi also looks like a typo - but maybe that's intentional?
Providing /wp-content/themes/visitsi_theme/listing-page.php is a physical file, then the WP front controller should ignore it.
The problem is,
I want to port my current website which is built upon CodeIgniter to WordPress. I do not want to hurt my google ranking and for that, I really need to map certain URLs to an existing file and for new URLs, I will let WordPress handle it in the default way. The main problem that arises is that I do not wish to change the existing domain. I want to redirect/map the files on the same domain from my existing CodeIgniter project.
Okay, let me make it a bit more clear about the state of my problem. I copied my existing CodeIgniter project into the WordPress root folder. Now, I will let the old URL being served from my CodeIgniter project and for all the new ones I will let WordPress handle it. I will also port the existing database to the new server and create a separate one for the WordPress installation.
So, how can I map my old URLs to the CodeIgniter?
My old URLs looks something like this,
http://www.example.com/site/blog/123/abc-xyz-wxy
I want to handle these URL from CodeIgniter file and the new URLs that will be created by WordPress will be handled by WordPress which would look like this,
http://www.example.com/abc-xyz-wxy
So, far this is how my .htaccess file looks like,
BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cms/wordpress/
RewriteRule ^site/blog/([0-9]+)/([a-zA-Z0-9-]+)/?$ codeignitor/index.php/$2
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /cms/wordpress/index.php [L]
</IfModule>
END WordPress
And this thing works absolutely fine, but what I want is more of a URL masking. I want to eliminate the CodeIgnitor folder name from the URL.
For selecting the "abc-xyz-wxy" string and redirecting, try using:
RewriteCond %{REQUEST_FILE} !-f
RewriteCond %{REQUEST_FILE} !-d
RewriteRule ^site\/blog\/123\/([a-z-]+) index.php\/$1 [NC,L] ^$1
Disclaimer: Never used CodeIgniter, so everyone feel free to correct.
In case anyone else happens upon this, I have a similar sounding use case where the application code resided inside /public_html/app/ and I wanted it redirect from /public_html/ but not show the app/ portion of it in the url. There was also an additional requirement to not route specific urls in this manner. The resulting file is below. Hopefully it helps someone on a similar journey.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
## SSL
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
## DO NOT ROUTE THESE DIRECTORIES
RewriteRule ^(path-1|path-2) - [L]
## ROUTE OTHER REQUESTS TO /APP
RewriteCond %{ENV:REDIRECT_STATUS} . [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} /(.+)
RewriteRule !\.[a-z0-4]{2,4}$ /app/index.html [NC,L]
RewriteRule (.*) /app/$1 [L]
</IfModule>
I've taken over a former site/domain, and set up a new site using Wordpress. The WP installation rewrites URL's to static ones, as you'd expect it to.
At the same time I want to preserve the former pages, as they have incoming links. I'm not interested in 301'ing them to "new" pages.
The old URL structure is /index.php?id=123, which I suspect is causing the problem with the WP .htaccess file. For reference, this is what it looks like:
# 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
I've tried adding the following:
RewriteRule ^([0-9]+).html index.php?id=$1 [R,L]
Doesn't work. Just redirects to site.com/?id=123 and shows the front page.
I should add that I plan on just adding these new pages as regular static HTML files in the format of 123.html, 321.html etc.
How do I use .htaccess to make this work together with the WP installation and what WP puts into the .htaccess file?
To clarify:
I want to have my 123.html static HTML page be index.php?id=123. When you access index.php?id=123 it should bring up 123.html, but show index.php?id=123 in the address bar. If you access 123.html it should 301 to index.php?id=123.
To map an URL with a querystring up to an actual file you'll need to use a RewriteCond to match the querystring itself (as RewriteRule doesn't):
Something along these lines ought to do it:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# retrieve X.html when index.php?id=X is requested
RewriteCond %{REQUEST_FILENAME} index\.php
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteCond %1.html -F
RewriteRule .* %1.html? [L]
# standard WordPress routing
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This will first check to see if you've got a request for index.php with a querystring like id=X.
Then it'll check to see if a file called X.html actually exists; I'm not 100% happy about having to use the more system hungry subrequest file check -F rather than the standard -f but I can't see a way around it in .htaccess in this case.
If X.html actually exists, it'll fetch that file whilst leaving the URL as index.php?id=X.
However if that file doesn't exist it'll fall back to standard WordPress no file, no directory routing to index.php
I'm not a WordPress expert but that should work; I guess the main WordPress controller uses $_SERVER['REQUEST_URI'] to determine the action.
Note: This won't, however, prevent people from accessing 123.html directly by going to the URL www.site.com/123.html - I kept falling into infinite loops and Apache 500 errors trying to prevent that :|
I am trying to create mod_rewrite rules to redirect the following url in my wordpress site:
www.mywebsite.com/pg/2/row/20/filter/all/filtercity/foo,bar
to
www.mywebsite.com/detail?pg=2&row=20&filter=all&filtercity=foo,bar
My problem is that wordpress included the following rules in the .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
I tried the following RewriteRule and it kind of works if I comment the last RewrireRule from Wordpress.
# 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]]
RewriteRule ^pg/([a-zA-Z0-9]+)/?$ ?pg=$2 [R]
</IfModule>
# END WordPress
The above works only for urls like
www.mywebsite.com/pg/2 => www.mywebsite.com?pg=2
A few questions:
1 - how can I configure .htaccess to process the url only when it finds the following keys
/pg and/or /row and/or /filter and/or /filtercity
for all other urls, it should execute the standard Wordpress RewriteRule . /index.php
2 - also the url can have all of the keys or only a few of them. For example:
/pg/2/row/20
/row/20/filter/all
how can I configure the .htaccess to process all the different combinations of keys?
3 - when I tried replacing
RewriteRule ^pg/([a-zA-Z0-9]+)/?$ ?pg=$2 [R]
with
RewriteRule ^pg/([a-zA-Z0-9]+)/?$ detail?pg=$1 [R]
I got a 404 error from the server. Not sure why. Any ideas?
Thank you.
EDIT 1:
I tried adding [L] to the end of my RewriteRule (see below)
RewriteRule ^pg/([a-zA-Z0-9]+)/?$ ?pg=$1 [R,L]
and moving the standard Wordpress rewrite rule to the next line
RewriteRule . /index.php [L]
After doing that I no longer get server 404 error. However the CSS files stop loading.
1 - how can I configure .htaccess to process the url only when it
finds the following keys
/pg and/or /row and/or /filter and/or /filtercity
Read this Rewrite URL with .htaccess for multiple parameters
The above answer helps you to solve your problem when have a standard url format.
2 - also the url can have all of the keys or only a few of them. For
example:
/pg/2/row/20
/row/20/filter/all
You are trying to do something out of URL semantics. When you try to access a resource, the path should be same every time. You can pass pg/0/ if you are on the starting page. But who can stop you from going out of URL semantics? :) In that case you have to have all the combinations as rules in your .htaccess. Follow the above solution, with all URL combinations it will work.
My Suggestions:
Don't Struggle with .htaccess if you are not familiar and your need is only URL rewrite (it is powerful though)
Pass everything to the index file and parse in your code, for your case have a look at this page http://codex.wordpress.org/Query_Overview
Okay I'm trying to use Lando (landocms.com) and I'm trying to get the pretty urls option to work.
Basically by default Lando creates link like: domain.com/index.php/page. Supposedly, there is a way to remove the index.php so the links become: domain.com/page. I have created an .htaccess as directed, however it does not work.
Here is the .htaccess I am using:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I have tried alot of variations, /index.php/, index.php? and plenty more but none work. According to HostGator everything should be fine. Any thoughts? I think I'm going crazy haha.
Thanks!
Rewriting for a CMS is a two-tier approach. First, you need to set your .htaccess (I have put a safer one here for you):
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ index.php [QSA,L]
Then, LandoCMS allows you to remove the index.php from the generated addresses, by means of turning on the appropriate setting in the administration panel. See this link for more information.
If the .htaccess content I've given you doesn't work, then simply use the one that the CMS has given you.
You want to remove the index.php part from any URL, but process the incoming, friendly URLs through index.php nevertheless
RewriteEngine On
# remove index.php and redirect client
RewriteCond %{ENV:REDIRECT_SEO} ^$
RewriteRule ^/?index.php/(.*) /$1 [R,L]
# process friendly URL
RewriteCond %{REQUEST_URI} !^/index.php/
RewriteRule .+ /index.php/$0 [E=SEO:1,L]
The environment setting E=SEO:1 prevents an endless loop.