I just setup a Wordpress in my server (www.albertotry.esy.es) and I added via FTP a new site files, but if I try to access the site, I don't see the index.html of the new site but the default Wordpress site.
I'm pretty sure there is a problem with the .htaccess file:
# Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working
RewriteBase /
# 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
What should I change to page that will display when I type "www.albertotry.esy.es"?
The .htaccess file you're using is the default WordPress one (except for that first line, which is a duplicate). It sends everything that is not a directory or file to index.php. If you want to load index.html when accessing the domain root only, then change the rule in question and add another after it:
Old Rule:
RewriteRule . /index.php [L]
New Rule:
RewriteRule !^$ /index.php [L]
The !^$ basically means "any string that is not empty" - in this case, the string is the request URI.
Then add a new rule below that one (you can also add it before, if you like - shouldn't make a difference):
RewriteRule ^$ /index.html [L]
Here, the ! is removed, which changes the meaning to "any request URI that is empty. As a result, requesting http://www.albertotry.esy.es/ will show the index.html file, but making any other request would rewrite to WordPress.
However, I believe that WordPress may check the content of the code between the comments # BEGIN and # END, so not sure if this is bulletproof. However, it does answer your question.
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.
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
I tried to rewrite a simple RewriteRule but i guess it doesn't turn up good. I created a htaccess file in wordpress wp-admin folder and i tried to rename the wp-admin directory name in my localhost.Here is the code i tried
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^wp-admin$ hello
Just for testing i had done this in my localhost. I want to start from simple pattern not complex pattern so i tried other simple pattern wp-admin and replacement as hello
RewriteEngine On # Turn on the rewriting engine
RewriteRule wp-admin hello
When i go to http://localhost/my_site/hello i can't able to direct to wp-admin for this am getting 404 error. When i try http://localhost/my_site/wp-admin am getting internal server error.
I think the rewrite rule is not good in my try. I have one more doubt should place the .htaccess file in the wp-admin directory or in the my site root directory in my_site or should i place in every directory which am trying to change the folder name on the fly.
What wrong am i doing here.Any help please?
RewriteRule ^hello(.*)$ wp-admin$1 [QSA]
Will change:
http://yourdomain.com/yourwp/hello
http://yourdomain.com/yourwp/hello/path/in/admin
to
http://yourdomain.com/yourwp/wp-admin
http://yourdomain.com/yourwp/wp-admin/path/in/admin
The QSA flag is useful for compatibility.
Here is my wordpress .htaccess with only one custom redirect, but you can understand the idea:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^login/?$ /wp-login.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Whenever I set the permanent links on wordpress to something other than the default
p=123
The links go to 404 pages
For example:
http://thewebsite.com/i/blog/2012/05/sample-post/
Would be linked as the blog post, but it would take you to a 404 result.
What can cause this kind of issue?
You need to have a rewrite in place.
In the root of your website, create a .htaccess file. This will be a hidden file but if you are using Filezilla as a FTP program you will be able to view it.
Put in it this:
# 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
Save it in the root of your website, ie, where wp-config goes and it should work.
If you have your website in a sub directory you will need to change the Rewrite base to reflect this instead of / for root.
Hope this helps!