I have Wordpress .htaccess where I have written a redirect rule. It is working perfectly. But now I am hosting the site in nginx. Where I came to know, there is no .htaccess. So I got a file named default in /etc/nginx/sites-enabled/. In this file I have to write.
But after written the redirect rule, nothing is happened.
I have written in .htaccess like this
RewriteRule ^business/([^/]*)/([^/]*)$ /business-profile/?id=$1 [L,P]
And now written in default file like this:
# nginx configuration
location /business {
rewrite ^/business/([^/]*)/([^/]*)$ /business-profile/?id=$1 break;
}
But cant get any result. Is there anything I left ? Please help.
# nginx configuration
location /business {
rewrite ^/business/([^/]*)/([^/]*)$ /aimber/business-profile/?id=$1 break;
}
I think you forgot "/aimber", the above should work.
Related
I got a domain ihakula.com, and I want to use blog.ihakula.com to point to my blog with wordpress.
And the path for wordpress is www.ihakula.com:9000/blog/, but I want in address bar which looks like no1.ihakula.com.
Now I use Nginx and .htaccess to made it, seems I got problems.
Here is the Nginx code:
# For ihakula blog
server {
listen 80;
server_name no1.ihakula.com;
location / {
proxy_pass http://www.ihakula.com:9000/blog/;
}
}
Here is the htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.ihakula\.com\:9000\/blog\/$
RewriteRule ^/?$ "http\:\/\/no1\.ihakula\.com\/" [P,L]
</IfModule>
Now I removed .htaccess file and changed the wordpress general config looks like this:
I can reach my wordpress console start with no1.ihakula.com/wp-admin. But when I hover any Post, the link shows below still start with www.ihakula.com:9000 looks like below:
Any ideas?
No, you do not need to do anything in your htaccess file. NGINX proxy can handle the request URL change automatically. What you are doing is actually making the sites to undertake infinite redirects.
What you should do more is to set the BLOG URL in WordPress to no1.ihakula.com, so that WordPress scripts will automatically give the URLs begins with no1.ihakula.com.
Alright, so I'm really struggling right now, I've tried everything, read articles and tutorials but I still don't know why this doesn't work.
I've got an index.php file:
echo "some test";
if(isset($para)) {
include $para . '.php';
} else {
echo "there's no parameter";
}
So if the user views the page with the parameter 'home' (http://mypage.com/test/index.php?para=home), he'll get the correct page. That does work.
.htaccess:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mypage.com$ [NC]
RewriteRule ^(.*)$ http://mypage.com/test/$1 [R=301,L]
RewriteBase /test/
RewriteRule ^([a-z]+)$ index.php?para=$1
But when I try to navigate using the rewritten link (http://mypage.com/test/home), the browser only outputs the included file and it completely ignores the index.php and its content.
Is there something wrong with my htaccess file? Or do I need to change some server configuration? Because I had a different htaccess file on a different webserver and it worked without any issues. But it didn't work on the webserver I'm using right now (sadly, I only have access to the htdocs folder).
EDIT: Just checked phpinfo, the page is running on PHP 5.3.28 on apache2.
Solved!
Problem solved. Adding 'Options -Multiviews' fixed the issue.
The hint here is:
The browser only outputs the included file and it completely ignores
the index.php and its content.
Try disabling mod_negotiation (Options -Multiviews) in the context where you want to do this remapping with mod_rewrite and within your script.
mod_negotiation is the most common reason "other" rewriting seems to be happening on your resources.
I wanna ask about .htaccess that could be change the url to be more simple. I have the url in my localhost like this:
localhost/spsb/index.php
and
localhost/spsb/index.php?page=student
The question is:
How can i change the url above being:
localhost/spsb
and
localhost/spsb/student
And where is the correct place to save the .htaccess file?
Thank's a lot for advice
I have been searching a lot everywhere but no one can solve my problem
Use URL Rewriting
For an Apache server:
First, you must activate the rewrite module
(How to active mod_rewrite)
Add those lines to your htaccess to enable rewrite engine
Options +FollowSymlinks
RewriteEngine On
And this line to rewrite the url as you want
RewriteRule ^spsb\/?$ spsb/index.php
RewriteRule ^spsb/([a-zA-Z]+)$ spsb/index.php?page=$1 [L]
For a Nginx server:
Put these lines in "Location" scope:
if (!-e $request_filename)
{
rewrite ^spsb\/(.*)$ spsb/index.php?page=$1;
}
Note: the location of .htaccess is relative to his level into the site structure, if he is inside the first level site/dir/ the contained rules are limited to site/dir structure
To be unlimited, i suggest to put it into the document root
...Or you can put the rules directly into you vhost configuration
How to check errors:
First have you restarted your server to apply the activated rewrite
modules
(rules from htaccess dont require a restart, only module
modification)
Add following lines to your htaccess after "RewriteEngine On":
RewriteLog "/var/log/apache2/{your_log_site...}" <-- put your path
RewriteLogLevel 7
Check by a "tail -f /var/log/apache2/you_log_site.errorlog" to see if
an error appear at resfresh page
I used to have my site hosted on a Apache server and had my htaccess file like this
RewriteEngine On
RewriteBase /
RewriteRule ^debs_public/(.*)\.deb$ counter.php?request=%{REQUEST_FILENAME}
I recently changed to a VPS and set the server up using nginx as per recommendations of it being faster. I've been struggling with the conversion of the htaccess file. I used a converter and got this line.
location /debs_public {
rewrite ^/debs_public/(.*)\.deb$ /counter.php?request=$request_filename;
}
but when I add this to my configuration it results in error 500 internal server error. Any suggestions as to what to change?
Note: What the counter does is count when a deb is downloaded from my Cydia repository. Works fine in Apache but fails in nginx.
Try something like below:
location /debs_public/ {
rewrite ^/debs_public/(.*)\.deb$ counter.php?request=$request_filename; break;
return 403;
}
Hopefully this may work.
Special Quote:
"if these directives are put inside the “/debs_public/” location, the last flag should be replaced by break, or otherwise nginx will make 10 cycles and return the 500 error:"
Refrence: http://nginx.org/en/docs/http/ngx_http_rewrite_module.html
I've had to move from testing on the live server, to testing locally on a virtual apache server. I've installed XAMPP just fine, downloaded and installed the wordpress files and the database. Everything looks great! The local version of my homepage is identical to the live version. There's only one problem: the homepage is the only page that works. When I click on one of the links i.e. the "about" page (http://localhost/wordpress/about/), I am redirected to the xampp control panel (http://localhost/xampp).
I have a good feeling this has to do with a problem with the "pretty links"/mod_rewrite rules. I made sure I brought over the .htaccess file, and it contains the rewrite instructions. The wordpress database has the proper permalink structure, and the httpd.conf file has the "RewriteEngine on" and the "FollowSymLinks" directives enabled. There has got to be some sort of rewrite problem here, although I am not ruling out something else stupid I might have done. Thanks for all your help!
-E
*Here is what the .htaccess looks like:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
In the httpd.conf, change the
DocumentRoot "/path/to/your/app/wordpress"
also
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/path/to/your/app/wordpress">
This should work, the path is absolute.
And do you have load the:
LoadModule rewrite_module modules/mod_rewrite.so
in httpd.conf??
If your server version works with a domain name, i.e: http://domainname.com is equivalent that http://localhost/wordpress the rewrite rules will be differents. post the rules here.
The problem is that wordpress does not believe in relative paths for some reason. There is an assumption that wordpress is running from the server root not a directory under the root (e.g. /var/www/wordpress will not work, but /var/www/ will).
The problem is with the .htaccess file they provide. It should re-write it to index.php and not /index.php. Change that line in your config and it will work.
What happens is that it tries to actually go to the default document root (in my case /var/www/index.php, which does not exist since I am using http://localhost/worpress which is an alias for ~/projects/worpress). You can check your error log and it will tell you where it is trying to look for the index.php file (which will return a 404 error).
I can go on a rant about how stupid it is that they do that and how bad the whole software design of wordpress is. But I will spare you that :).