简体   繁体   中英

.htacess url rewriting not working

I am trying to change http://womenhealthanddiet.com/article_info.php?id=238 to women-health-article/ . I tried different tutorials and looking for answers on Stack Overflow, but whatever I do to the url it does not change. I am using Godaddy as a webhost. What should I do?

Options +FollowSymlinks
RewriteEngine on
#Fix Rewrite (-|-) this works as a fix for crazy ass godaddy, 
#thanks david walsh @ (davidwalsh.name)!
Options -Multiviews
RewriteRule ^women-health-article/([-_!~*'()$a-zA-Z0-9]+)/$ article_info.php?id=$1 [L]

This will statically redirect to article_info.php?id=238

RewriteEngine on
RewriteRule   ^(.*)/women-health-article/$  article_info.php?id=238  [R,L]

This will dynamically redirect based on an id following the url.

RewriteEngine on
RewriteRule   ^(.*)/women-health-article/(.*)$  article_info.php?id=$2  [R,L]

for me im always using this code which is work really fine for me

RewriteEngine On

RewriteRule ^women-health-article-([a-zA-Z_0-9-/]+).html$ article_info.php?id=$1
RewriteRule ^women-health-article-([a-zA-Z_0-9-/]+).html/$ article_info.php?id=$1

using this code inside .htaccess file will give you this result in url

http://you-domain-name.com/women-health-article-238.html

and if you want to change the url to be more nice you can change your method and make a table inside your database lets say the table name is article_slug now this article slug will have article slug just like the id.

now if you make an article you should enter the slug of this article and using it just like you use id

example

you have article title (Fitness Train For Women) and the slug is (fitness-women-train) so the php will be

the URL as .htaccess i write before

http://you-domain-name.com/article-fitness-women-train.html

<?php

$getslug = $_GET['slug'];

$query = mysql_query("SELECT * FROM table WHERE article_slug = '$getslug' ");
$result = mysql_fetch_assoc($query);

?>

and the .htaccess file for this example will be

    RewriteEngine On

    RewriteRule ^article-([a-zA-Z_0-9-/]+).html$ article_info.php?slug=$1
    RewriteRule ^article-([a-zA-Z_0-9-/]+).html/$ article_info.php?slug=$1

so that's it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM