Wordpress after migration doesn't work - php

I had problems with WordPress migration from one server to another, and generally now it works but I have many smaller problems..
Before I use domain oldexample.com and now i use domain newexample.com/something . Generally everything on the page works but changing language isn't work (qTranslate plugin).
I think that I found the reason of this - in admin menu I found in some places situation that href links start from "/" for example: "/wp-admin/..." and in result it change the URL from newexample.com/something/wp-admin to newexample.com/wp-admin. I see this problem in qTranslate settings links and when I want delete some plugins. I get the error message "404 Not Found - nginx/1.4.5" in results...
Did you see this problem before? Maybe I should change something in WordPress core files? .htaccess? Now it looks like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?newexample\.com\/something$ [NC]
</IfModule>
# 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

After long time I find the solution! All "href" are generated by using $_SERVER['REQUEST_URI'], and this variable show only the rest part of the path (without /something/. I add to wp-settings.php this part of code: $_SERVER['REQUEST_URI'] = '/something'.$_SERVER['REQUEST_URI']; (on the very beggining) all forms generate good path.

Related

How to make an external Wordpress Main Page?

Actually I am running a Wordpress website with a simple template.
Now for SEO and Speed optimization purposes I would like to make a custom HTML page super simple and well optimized but that is not part of the Wordpress structure.
Basically, my own HTML page.
How can I have my Wordpress thinking the main page is that HTML created page as Main page and the rest of the website managed by the Wordpress ?
My answer requires an Apache or Litespeed server (and possibly others) with mod rewrite enabled, and where AllowOverride has not limited your use of .htaccess file.
See: https://codex.wordpress.org/htaccess#General_Examples
According to the WordPress documentation on that page, if you are using an .htaccess file to handle "pretty permalinks", then it creates and uses the following basic .htaccess file:
# 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 this code does is redirect all requests that are not for an actual file or directory to the index.php file. You can modify this easily and achieve what you want. Simply changing it to something like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp_index.php [L]
</IfModule>
# END WordPress
That change would redirect all requests to wp_index.php instead of index.php. So you would make that change, and then rename your index.php file to wp_index.php.
Once that is done, you can create a new index.php file and its contents can be plain HTML. Don't worry about the .php file extension. When somebody goes to your website, if they go to your homepage, the server will serve up the index.php file. For all other requests the server will use wp_index.php and WordPress will handle the request.
Please keep in mind that there are some differences in how .htaccess files work, depending on your server. If my changes don't immediately work, tweaking the .htaccess file contents may be necessary.

.htaccess Search Engine & User Friendly URL's

Site Structure:
SITE ROOT
/Desktop/ - For everything seen at domain.com
/Mobile/ - For everything seen at m.domain.com
/Admin/ - For everything seen at admin.domain.com
.htaccess
RewriteEngine On
Options FollowSymLinks
RewriteRule ^([-_a-zA-Z0-9]*)/([-_a-zA-Z0-9]*)/([-_a-zA-Z0-9]*)$ $1.php?id=$2&name=$3
I've tried placing this at SITE ROOT and /Desktop/.
The Problem
I've set up a testing page domain.com/company.php which simply has <h1>Hello World</h1> within.
Upon going to: http://domain.com/company.php?company_id=74&name=DesignSourceLtd
"Hello World" displays
Upon going to: http://domain.com/company/74/DesignSourceLtd
A 404 page shows.
Question(s)
How do I make my URL search engine & user friendly and all preceding 'pages' of company show the company.php template?
Solution 1
You can handle all the URIs within index.php by creating .htaccess file like this (So you can treat any parameter as you want and other benefits ) :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond &{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,NC,L]
And access parameters with explode('/',$_SERVER['REQUEST_URI']) and you can include company.php
Solution 2
You can create a spesific handle for company.php
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond &{REQUEST_FILENAME} !-d
RewriteRule ^company\/([-_a-zA-Z0-9]*)\/([-_a-zA-Z0-9]*)$ company.php?company_id=$1&name=$2[QSA,NC,L]
Solution 2 doesn't catch first url parameter because your GET Queries are spesific for company.php
Your options should be Options +FollowSymLinks - not sure if that will affect the outcome, however. Your forward slashes should also be escaped. Try regex101.com to test.
See https://regex101.com/r/PQpiLt/1

.htaccess redirect from Wordpress URL to Normal site URL

I have rebuild a site. The old site was WordPress and new site is normal php site with same amount of pages.
I do not want to lose the outside plus google links to this pages and need to do a redirect in .htaccess
I know how to do this with normal links e.g. www.domain1.com/guesthouse.html to www.domain2.com/guesthouse.php
I do not understand the wordpress link with no ".php or .html" at the end of the link.
The old link is www.doamin.com/guesthouse/ (only this without .html or .php)
New link must be www.domain.com/gusethouse.php
The WordPress .htaccess file looks like 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`
Can I delete the above code and replace with
`Redirect 301 /guesthouse/ http://www.domain.com/guesthouse.php`
or must I add it to the existing .htaccess code.
Do not know how to do it right, please help.
Thank you.
The .htaccess file will execute prior to your PHP interpreting engine running. This means that you're higher in the execution chain than the Wordpress software.
If you're not going to use your Wordpress website anymore, then there's no reason to send requests to it!
Instead, just simply remove all of that code, and rewrite the URL's accordingly.

Changing the actual URL without changing display URL using htaccess [duplicate]

So, I've this problem:
Base Website located at http://example.com/
Second Website located at http://example.com/web2/
People making various requests to the second website like
http://example.com/myWeb/pg1 and http://example.com/web2/pg2
Recently and due to some other issues I need to have a custom new path for the second website but also keep the first one working.
The ideia is to allow users to access the second website over the two following addresses:
http://example.com/web2/
http://example.com/alternative-url-web2/
The folder /web2/ actually exists on the server, but how can I simulate the folder /alternative-url-web2/ and "redirect" the requests to /web2/?
Please note I don't want the URL on the browser to change, this must be a "silent redirect". And I also make sure that all other requests like http://example.com/other are not redirected by the second website.
Thank you.
Update:
According to #anubhava I could simply solve this issue by adding in my .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^alternative-url-web2(/.*|)$ /web2$1 [L,NC]
This is probably working fine but I noticed the following:
http://ex.com/alternative-url-web2 is redirected to http://ex.com/web2/ (changing browser URL);
http://ex.com/alternative-url-web2/ is redirected to http://ex.com/(changing browser URL);
http://ex.com/alternative-url-web2/someRequest works fine and does NOT change the browser URL;
http://ex.com/alternative-url-web2/index.php works fine and does NOT change the browser URL;
Site Note:
At /web2/ there's an .htaccess that might be cause the wired redirect behavior above... So here is the file contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
Can the internal RewriteRule to index.php be causing all this? If yes, how can I fix it?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^alternative-url-web2(/.*|)$ /web2$1 [L,NC]
Alternate code:
RewriteRule ^alternative-url-web2/?$ /web2/ [L,NC]
RewriteRule ^alternative-url-web2/(.+)$ /web2/$1 [L,NC]
This is a pretty simple rewrite. In the htaccess file in your document root, just add the following:
RewriteEngine On
RewriteRule ^alternative-url-web2/?(.*)$ /web2/$1 [L]
Unlike a redirect, which makes the browser/client send a new request for a new URL (thus changing what's in the browser's location bar), a rewrite happens entirely on the server's side.
By the way, in order to follow the trail of htaccess redirects, you could add something like this to each of them:
Header add X-Remark-Rewrite "/path.to/htaccess"
You can inspect these in the response in the developer tools.

How can I make pretty URL link with wordpress?

I've got some questions about making pretty URL link.
On my website home page, I have a drop down list of text (city and state) which is going to be my parameter. I'm sending the value through GET METHOD to a WordPress template page which system will display contents based on passed value. The display content part is working successfully, however, I have some question about link.
Right now, the link of the page is showing
www.mydomain.com/list/?state=NY&city=Newyork or
www.mydomain.com/list/?state=IL&city=Chicago
I prefer the link to be the following pretty format, ...
www.mydomain/list/NY/Newyork
www.mydomain/list/IL/Chicago
I have researched on many sites and found recommendation on using htaccess. I'm using the following code but still link doesn't get changed to the pretty format.
# 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]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([0-9]+)/?$ ?district=$1
RewriteRule ([0-9]+)/([^/]+)/?$ ?district=$1&templename=$2 [L]
</IfModule>
# END WordPress
What you're looking for should be done using wordpress' add_rewrite_rule function. You can read more about it here
Here's a sample that may be what you're looking for:
<?php
add_rewrite_rule('list/([0-9|a-z|A-Z]*)?/?([0-9|a-z|A-Z]*)?/?([0-9|a-z|A-Z]*)?/?([0-9|a-z|A-Z]*)?','index.php?$matches[1]=$matches[2]&$matches[3]=$matches[4]','top');
?>
To explain things in detail:
First, we declare a regular expression to match any get parameters after the "list" slug. (i.e: www.mydomain.com/list/)
Secondly, we declare how wordpress should interpret it. The file will always be index.php for wordpress. The parameters will line up like www.mydomain.com/list/state/IL/city/Chicago which will translate to www.mydomain.com/list/?state=IL&city=Chicago in your code for you to use your $_GET parameters
top tells Wordpress that these rules have precedence over wordpress' own rules.
You may need to call flush_rewrite_rules( false ) or $wp_rewrite->flush_rules() to flush the rules and have your changes come into effect

Categories