php URL rewrite wamp - php

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

Related

Mod re write breaking url

Update I have re- done the code and folder system of my mod re write on localhost still nothing
the link only shows like this
http://localhost/cms/member/profile.php?member=10308
my entire .htaccess file
RewriteEngine On
RewriteRule ^cms/member/([^/]*)$ /cms/member/profile.php?member=$1 [L]
when i click on the link it does nothing. if i change in the browser to
http://localhost/cms/member/10308
it says page cannot be found.
Update the problem was this peice of code causing it to not display right
<?php
if(empty($_GET['member']) || $_GET['member'] <1000 ) {
redirect(ROOT_URI);
exit;
}
?>
But i need this code.
the url will work but i need to type it in manually it wont automatically change the url
As you are using an .htaccess file which is placed under the directory "cms", you should use the following directives:
RewriteEngine On
RewriteRule ^member/([^/][0-9]*)$ member/profile.php?member=$1
This will send the request http://localhost/cms/member/(any-number) to http://localhost/cms/member/profile.php?member=(any-number)
Note:
mod_rewrite should be enabled.
In httpd.conf (or apache2.conf), replace AllowOverride None by AllowOverride All to enable .htaccess
Restart Apache server.

.htaccess file not working at all

I am trying to redirect anyone when he is trying to hit "192.168.21.3:8080/ping" to "192.168.21.3:8080/ping.php" via creating a .htaccess file with following code in it:
//301 Redirect Old File
Redirect 301 http://192.168.1.234:8080/ping http://192.168.1.234:8080/ping.php
Also, following line in httpd.conf has been un-commentated:
LoadModule rewrite_module modules/mod_rewrite.so
Please help!
i am still learning the basics myself however i will have a try to help you out, If you let me know how you get on.. i can re-edit my answer should the solution not work.
You can either redirect all traffic to the page named ping.php or as per your question you can redirect a specific IP address to ping.php.
add the code below to your .htaccess file.
RewriteEngine On
RewriteCond %{REMOTE_ADDR} 192\.168\.21\.3
RewriteCond %{REQUEST_URI} !/ping\.php$
RewriteRule $ /ping.php[R=301,L]
Alternatively you could take a look here as this may also help you out: https://perishablepress.com/permanently-redirect-a-specific-ip-request-for-a-single-page-via-htaccess/
Thanks
Just add
RedirectMatch ^/ping$ http://192.168.1.234:8080/ping.php
to your www-root .htaccess. Nothing more.

htaccess not working on windows server 2003 with apache installed

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

Configure rewriting url in localhost with EasyPHP

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.

Local Apache Server mod_rewrite/pretty links issue

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 :).

Categories