Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'mod_rewrite'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 11 results

  1. Hello people, I am attempting to send the $row['name'] value retrieved from my database which contains spaces, however Mod_Rewrite Does Not Replace Spaces In URL To Plus (+) Symbol Nor Hyphen (-), anyone know how to fix this ? here is my url to send to match my url in mod_rewrite: <a href="/html/browse/' . $type . '/' . $subcategory . '/' . $row['name'] . '/' . $row['id'] . '" class="button">view product</a> here is my rule in mod_rewrite : RewriteRule ^browse/(clothing|jewellery|accessories)/([A-Za-z]+)/([A-Za-z]\+\-]+)/([0-9]+)/?$ viewitem.php?type=$1&subcategory=$2&name=$3&id=$4 [L] Thanks in advance.
  2. I am modularizing a existing site as discussed in Chapter 2. All is working fine but I cannot seem to find the correct rewrite script for my .htaccess relative to rewriting (or forwarding existing) links that have been indexed in search engines. An example: http://www.example/productdetail.php?id=100 (as indexed by Google) should display as http://www.example/product-detail/100/ but instead is displaying in address bar as http://www.example/product-detail/?id=100 (and obviously no page is found) My current .htaccess is: RewriteEngine On RewriteRule ^([^/]*)/$ /index.php?p=$1[L] RewriteRule (product-detail)/([^/]*)/$ /index.php?p=$1$id=$2 I also have a URL redirect for this page: Redirect 301 /productdetail.php http:www.example.com/product-detail/ Any assistance would be appreciated.
  3. <?php // script 18.6 if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form. // Need the database connection: require (MYSQL); // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $fn = $ln = $e = $p = FALSE; // Check for a first name: if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) { $fn = mysqli_real_escape_string ($dbc, $trimmed['first_name']); } else { echo '<p class="error">Please enter your first name!</p>'; } // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Please enter your last name!</p>'; } // Check for an email address: if (filter_var($trimmed['email'], FILTER_VALIDATE_EMAIL)) { $e = mysqli_real_escape_string ($dbc, $trimmed['email']); } else { echo '<p class="error">Please enter a valid email address!</p>'; } // Check for a password and match against the confirmed password: if (preg_match ('/^\w{4,20}$/', $trimmed['password1']) ) { if ($trimmed['password1'] == $trimmed['password2']) { $p = mysqli_real_escape_string ($dbc, $trimmed['password1']); } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { echo '<p class="error">Please enter a valid password!</p>'; } if ($fn && $ln && $e && $p) { // If everything's OK... // Make sure the email address is available: $q = "SELECT user_id FROM users WHERE email='$e'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_num_rows($r) == 0) { // Available. // Create the activation code: $a = md5(uniqid(rand(), true)); // new line include('includes/lib/password.php'); // new line $hash=password_hash($p, PASSWORD_BCRYPT); // Add the user to the database: $q = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', '" . password_hash($p, PASSWORD_BCRYPT) . "', '$fn', '$ln', '$a', NOW() )"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Send the email: $body = "Thank you for registering at <whatever site>. To activate your account, please click on this link:\n\n"; $body .= BASE_URL . 'activate/x=' . urlencode($e) . "&y=$a"; mail($trimmed['email'], 'Registration Confirmation', $body, 'From: mymail@sample.com'); // Finish the page: echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>'; include ('includes/footer.html'); // Include the HTML footer. exit(); // Stop the page. } else { // If it did not run OK. echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; } } else { // The email address is not available. echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>'; } } else { // If one of the data tests failed. echo '<p class="error">Please try again.</p>'; } mysqli_close($dbc); } // End of the main Submit conditional. ?> <h1>Register</h1> <form action="http://www.sample.com/register/" method="post"> <fieldset> <p><b>First Name:</b> <input type="text" name="first_name" size="20" maxlength="20" value="<?php if (isset($trimmed['first_name'])) echo $trimmed['first_name']; ?>" /></p> <p><b>Last Name:</b> <input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed['last_name'])) echo $trimmed['last_name']; ?>" /></p> <p><b>Email Address:</b> <input type="text" name="email" size="30" maxlength="60" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" /> </p> <p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" value="<?php if (isset($trimmed['password1'])) echo $trimmed['password1']; ?>" /> <small>Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.</small></p> <p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" value="<?php if (isset($trimmed['password2'])) echo $trimmed['password2']; ?>" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Register" /></div> </form> <?php # Script 18.7 - activate.php // This page activates the user's account. require ('includes/config.inc.php'); $page_title = 'Activate Your Account'; include ('includes/header.html'); // If $x and $y don't exist or aren't of the proper format, redirect the user: if (isset($_GET['x'], $_GET['y']) && filter_var($_GET['x'], FILTER_VALIDATE_EMAIL) && (strlen($_GET['y']) == 32 ) ) { // Update the database... require (MYSQL); $q = "UPDATE users SET active=NULL WHERE (email='" . mysqli_real_escape_string($dbc, $_GET['x']) . "' AND active='" . mysqli_real_escape_string($dbc, $_GET['y']) . "') LIMIT 1"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); // Print a customized message: if (mysqli_affected_rows($dbc) == 1) { echo "<h3>Your account is now active. You may now log in.</h3>"; } else { echo '<p class="error">Your account could not be activated. Please re-check the link or contact the system administrator.</p>'; } mysqli_close($dbc); } else { // Redirect. $url = BASE_URL . 'index.php'; // Define the URL. ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } // End of main IF-ELSE. include ('includes/footer.html'); ?> I am modularizing a site that uses the registration (18.6) and activation (18.7) scripts from Chapter 18. All works fine until I try to rewrite activation.php to activation.inc.php and place it in the modules folder. When the activation e-mail comes and I click on the link, I receive a 404/Page Not Found. I am using the following in my .htaccess: RewriteEngine On RewriteRule ^(home|register)/?$ index.php?=$1 [L] RewriteRule ^(activate)/?$ index.php?p=$1&x=$2&y=$3 [L] As mentioned, registration works to the point of all data being inserted into database and the "Registration Confirmation" e-mail being received. It strongly appears to be a matter of my mod_rewrite syntax. Any suggestions as to where I am in error would be appreciated. Thank you.
  4. I have been working on the project in Chapter 2. So far everything is running well. I am currently trying to get the mod_rewrite capability in .htaccess working. But seem to be having problems. Let me explain my setup: My root_document folder is as follows: C:\Program Files (x86)\Zend\Apache2\htdocs\PHPadvanced\project_1 The changes that i have made to the httpd.conf is as follows: <Directory "C:/Program Files (x86)/Zend/Apache2/htdocs/PHPadvanced/project_1"> AllowOverride All </Directory> I have placed this at the bottom of my httpd.conf file. I have not changed the settings that are earlier in this file: <Directory "C:\Program Files (x86)\Zend\Apache2/htdocs"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory> I looked at several forums and there were many suggestions to change this part of the .conf file. However, I understood that by adding the code that i did add to the end of the file, i have basically just controlled the amount of space that i have opened up to being controlled from the .htaccess file. I have placed my .htaccess file in both the main htdocs root folder, but also in the project_1 root_folder. This is also where my index.php file is. My contents of the .htaccess file are as follows: # project_1 .htaccess <IfModule mod_rewrite.c> RewriteEngine on RewriteBase /PHPadvanced/project_1/ RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1 </IfModule> I am now trying to go to my browser and type in http://localhost/PHPadvanced/project_1/about But this is just bringing up the following message. Not Found The requested URL /PHPadvanced/project_1/about was not found on this server. I am struggling as i am not quite sure where i am having problems. PLEASE HELP!!!
  5. I am trying to make SEO friendly URLs of using apache mod_rewrite. My normal URLs is something like this - index.php?p=about index.php?p=contact index.php?p=this My expecting SEO friendly URLs should be something similar to this - localhost/php_advance/ch02/about localhost/php_advance/ch02/contact localhost/php_advance/ch02/this I tried it with creating a .htaccess file and doing some changes to my apache httpd.conf file. This is my .htaccess file <ifModule mod_rewrite.c> # Turn on the engine: RewriteEngine on # Set the base to this directory: RewriteBase /php_advance/ch02/ # Redirect certain paths to index.php: RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1 </ifModule> And also, At the end of the httpd.conf file, I added some code like this - <Directory "C:/wamp/www/php_advance/ch02"> AllowOverride All </Directory> NOTE: I am using WAMP server and Windows 07 But this coding is not working for me. Hope someone will help me out. Thank you.
  6. First, I've been pulling my hair trying to resolve this problem, I really would like to be able to have clean urls. First I running on Windows 8 using XAMPP ( I now wish I was using Linux ). I made sure that my .htaccess file does indeed start with a period Here the .access file # Script 2.7 - .htaccess<IfModule mod_rewrite.c> # Turn on the engine:RewriteEngine on # Set the base to this directory:RewriteBase /chapter02/ # Redirect certain paths to index.php:RewriteRule ^(about|contact|this|that|search)/?$ index.p </IfModule> here's the bottom of my httpd.conf file # AJP13 Proxy<IfModule mod_proxy.c><IfModule mod_proxy_ajp.c>Include "conf/extra/httpd-ajp.conf"</IfModule></IfModule><Directory "c:/xampp/htdocs/php_test/chapter02"> AllowOverride All</Directory> and here's part of my config.inc.php file // Determine location of files and the URL of the site:// Allow for development on different servers.if ($local) { // Always debug when running locally: $debug = TRUE; // Define the constants: define('BASE_URI', 'c:/xampp/htdocs/php_test/chapter02'); define('BASE_URL', 'http://localhost/php_test/chapter02/'); define('DB', '/path/to/mysql.inc.php'); } else { define('BASE_URI', '/path/to/live/html/folder/'); define('BASE_URL', 'http://www.example.com/'); define('DB', '/path/to/live/mysql.inc.php'); } Like I said I've been pulling my hair out, stopping apache server, restarting it, modifying code, restarting (even rebooting my machine once). I even did a Google search trying various "fixes" and even this forum. Any help would be greatly appreciated. I know it is probably something stupid that I'm doing. Best Regards, John
  7. Hi Larry, First of all this Effortless E-Commerce has been very helpful in my understanding of build e-commerce sites. I truly feel it is the best resource out there on the subject. I am new to PHP and MySQL, and your books have helped me learn in a short period of time. My question has to do with .htaccess and mod_rewrite. I am using Yahoo Small Business as a host (for now), but they do not allow .htaccess. I know it would be easier for me to change hosting services, but I cannot at the moment, so I need to find a way around this problem. You stated on page 175 under the Tips sidebar that 'If you can’t use mod_rewrite on your server, just skip this section and change every URL in the HTML files accordingly.' Where exactly would I change these URLs? Is there an alternative to this similar to the alternatives for the stored procedures? Thank you in advance.
  8. I think I was following the instructions very precisely, but the result isn't what it was supposed to be. Going to mysite/about/ doesn't land me on the about page (which I have created just to see what would happen, even though the book doesn't mention anything about creating it.) Repeated clicks on the links, modified as suggested in the book, result in URLs like this: index.php/about/index.php/this/ index.php/about/index.php/this/index.php/that/index.php/about/index.php/that/ and so on. I'd appreciate some help with this from a knowledgeable person.
  9. I am trying to use mode_rewrite in my project but it is not working. httpd.conf Settings: <Directory "C:/xampp/htdocs/mysite/blog"> AllowOverride All </Directory> .htaccess Settings: <IfModule mod_rewrite.co> RewriteEngine on RewriteBase /mysite/blog/ # For article: RewriteRule ^article/([0-9]+)/?$ article.php?id=$1 </IfModule> How can I fix this problem? Thank you.
  10. I've been thinking about my ModRewrites. I am adding new files every day. There will be about 150 total. But I might be adding a new product line that could increase it to about 400. I'm not sure until I get details and I don't know if that matters. What I'm thinking about is that all these modrewrites are going to slow things down. What I'm doing now works great and it gives user ability to type abbreviations. But if it will slow things down, should I even do it that way? What I really only need, is when my program calls up a name, the modrewrite finds the correct file. My program uses the canonical name which is what I want. Would it make sense for me to do this, if this can even be done: All my file names start with a condition name followed by hyphen followed by treatment.php: condition-name-treatment.php, and my code calls the file without the .php. Could I say [a-z\-] followed by "-treatment" gets .php added. If this can be done would it be faster? So would it be worthwhile doing? I should mention there are a few other files that don't use the condition-treatment format so this modrewite shouldn't catch those. Here is example of what I do now: RewriteRule ^head|migra[a-z_\-\./]*$ migraines-treatment.php
  11. I'm trying to do mod_rewrite like this: RewriteEngine On RewriteRule ^cancer/?$ cancer.php RewriteRule ^ptsd/?$ptsd.php I have my testing directory, named minus, so the same code should be at adviceofthequeen.com and adviceofthequeen.com/minus/ I put this code into the .htaccess file in minus directory and when I type into browser: http://adviceofthequeen.com/minus/cancer the cancer.php page comes up correctly. But when I type into browser: http://adviceofthequeen.com/minus/cancer/ the cancer.php pages comes up but without the style sheet and images. So I also put this same code into .htaccess file above the minus directory (the real live code) and when I type into browser: http://adviceofthequeen.com/ it throws a 500 Internal Server Error. I'm pretty sure that if I ask hosting tech support about this they will suggest I use the cpanel redirect. I want to do this for all my files and now there is only 6 but there could be maybe about 50 when I'm done. It doesn't seem that redirect is the best way to do this. Is there any syntax error in my mod_rewrite? There was nothing in the .htaccess files except directory protection in the minus directory which is temporarily not on right now. Apache version 2.2.21 PHP version 5.2.17 MySQL version 5.0.92-community-log
×
×
  • Create New...