I'm trying to configurate .htaccess to set rewriting URL in localhost, with EasyPHP, but all I get is 404 error.
My local website is C:\Projects\Test\, and in EasyPHP I created a new alias with "Test" name poiting to this location. So, to access this website, I type 127.0.0.1:8080/test in the browser.
The .htaccess file is addressed in the root of this website (C:\Projects\Test\ .htaccess). It's just an example, where everything typed redirects the user to "/user/inicial.php".
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-z,0-9,A-Z,_-]+)$ /user/inicial.php
</IfModule>
I've also follow these steps to configure apache to be able to run rewriting URLs:
Changed httpd.conf file (addressed in C:\Programs\EasyPHP-12.1\conf_files) where:
Uncomment "LoadModule rewrite_module modules/mod_rewrite.so" line;
Change all "AllowOverride None" sentences to "AllowOverride All".
It's everything that I have done. If someone has more options to give me, I'll really appreciate.
Related
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 have a QNAP NAS with Apache correctly installed. Some pages are linking fine except for ones using any RewriteRule. All other pages are linking correctly to mysql and displaying fine its the ones with any RewriteRule, these are showing up as a 404 error like this:
The requested URL /share/CACHEDEV1_DATA/Web/clients/hembury4x4/couk/view-sitemap.php was not found on this server.
URL = http://192.168.1.210/Web/clients/clientname/sitemap.html
FILE= http://192.168.1.210/Web/clients/clientname/view-sitemap.php
My rule is quite simply: RewriteRule ^sitemap.html$ view-sitemap.php [NC,L]
I have copied all the site files from my computer where the redirect was working perfectly. What do i need to add on my htaccess file?
Thanks in advance
First, apache should have rewrite module. It should present in the output of httpd -M command.
Then you should allow .htaccess files. This can be made by adding AccessFileName .htaccess directive (if it's absent) to your httpd.conf file. Also check you have this section:
<Directory />
AllowOverride All
</Directory>
I have Apache installed.
I have LoadModule rewrite_module modules/mod_rewrite.so un-commented and set every instance of AllowOverride None to AllowOverride All in http.conf.
My site is in a subfolder, so its like http://123.34.56.123/Website/ to get to it.
.htaccess file
RewriteEngine On
RewriteBase /Website/
Options +FollowSymLinks
RewriteRule ^index.php http://www.google.com/? [R=301,L]
But when I visit the above address, it does not redirect to google.com and, instead, shows the contents of index.php.
Update:
Added junk to the .htaccess file and http.conf to force a internal server error, and it still just goes to my index.php.
Did a var dump on $_SERVER, and found this out: ["SERVER_SOFTWARE"]=> string(17) "Microsoft-IIS/6.0", but can't find any program files around IIS.
Based on your question, some probable causes of your problem:
Incorrectly named .htaccess file. You call it an "htaccess file" repeatedly in your post. The filename must be .htaccess (with the leading .).
File in the wrong directory. Make sure this file is in the root directory of your site.
The module you need to enable isn't mod_userdir.so, but mod_rewrite.so. Look for a line like this one: LoadModule rewrite_module modules/mod_rewrite.so
Make sure the [R=301,L] is on the same line as the RewriteRule to which it applies, or you will have errors.
Also, don't do a 301 on this, even for testing -- it will permanently redirect traffic to your index.php to Google. That's what a 301 does. For testing, use a 302.
Converting comment to an answer, if your update to httpd.conf mysteriously fail to change anything on Windows, edit httpd.conf as Administrator (not a member of the administrator group, Administrator) to avoid Windows silently doing "data redirection" of httpd.conf edited out of Program Files.
http://blogs.windows.com/windows/archive/b/developers/archive/2009/08/04/user-account-control-data-redirection.aspx
I want to implement URL rewrite in wamp.
My ugly link is:
http://mysite.com/news.php?id=4654654&title=asdasdasdas-das-dasd-as-da-sda-d-asd-ads-as-da-sd
I want pretty URL to be
http://mysite.com/4654654/asdasdasdas-das-dasd-as-da-sda-d-asd-ads-as-da-sd
Using online generator on www.generateit.net/mod-rewrite/ for my link I get this .htaccess result:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /news.php?id=$1&title=$2 [L]
in wamp apache rewrite_module is checked, in httpd.conf I change AllowOverride None to AllowOverride All. I removed # sign from LoadModule rewrite_module modules/mod_rewrite.so
But when I click on hred with link like this http://mysite.com/4654654/asdasdasdas-das-dasd-as-da-sda-d-asd-ads-as-da-sd , I receive Not Found error The requested URL /myfolder/4654654/asdasdasdas-das-dasd-as-da-sda-d-asd-ads-as-da-sd was not found on this server
site root folder is in c:/www/myfolder
Can someone tell me what should I do to work this?
Thanks
EDIT
should I made some changes in my php file except href values?
create a new .htaccess file in your web root directory i.e c:/www/myfolder and place the code in it. and it should work.
The RewriteRule-part should start in a new line under RewriteEngine on.
There is a good beginner's guide with explanations at:
http://www.workingwith.me.uk/articles/scripting/mod_rewrite
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 :).