Jump to content

[SOLVED] What is wrong with my mod rewrite?


pneudralics

Recommended Posts

Trying to attempt to mod rewrite but just getting error 500.

 

What I'm trying to get is: backgrounds/Animals/Birdy/29

 

So will the first set of A-Z replace Animals or category? If it replaces Animals..does it just ignore category?

 

RewriteEngine on
RewriteBase /

RewriteRule ^backgrounds/([A-Z]+)/([A-Z]+)/([0-9]+)$ backgroundsimage.php?category=Animals&title=Birdy&id=29

Link to comment
Share on other sites

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^backgrounds/([A-Z]+)/([A-Z]+)/([0-9]+)(/?)$ backgroundsimage.php?category=$1&title=$2&id=$3 [NC,L]
</IfModule>

 

This code actually work (tested). I replace the GET value with $var. Added (/?) in the regular expression so you can use both with or without a trailling slash like that :

http://www.example.com/backgrounds/animals/birds/70/

http://www.example.com/backgrounds/animals/birds/70

 

Added a NC flag mean case insensitive (no case)

Added L flag mean when it match pattern apply it and stop there (don't read other rules in .htaccess)

 

My best guess is that you are missing the 'Options +FollowSymLinks' needed by mod_rewrite or mod_rewrite isn't installed.

Link to comment
Share on other sites

Where did you test it? I tried WAMPSERVER AND XAMMP and it still doesn't work. I don't get any errors, it just doesn't rewrite.

 

what do you do in order to try it ?

 

Click on the links on the page that are dynamic..

 

When I type it in the browser it works.

 

Now if I have this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^backgrounds/$ backgrounds.php [NC,L]
</IfModule>

 

and I type http://localhost/backgrounds/

 

all my links are now under the backgrounds directory so none work anymore.

 

Isn't mod_rewrite suppose to rewrite the url so if I type http://localhost/backgrounds.php it'll change that to http://localhost/backgrounds/ ?

 

Link to comment
Share on other sites

mod_rewrite will not rewrite urls already within a webpage. You have to modify your urls manually.

 

.htaccess file now have this in it

RewriteRule ^backgrounds/(.*)$ backgroundscategory.php?category=$1 [NC,L]

 

php file with links now have this

echo "<a href=\"backgrounds/$categorylink\" class=\"backgroundsfg\">$categorylink</a><br />";

 

Everytime I click on the link it keeps adding backgrounds/...so my url will eventually look like:

 

http://localhost/backgrounds/backgrounds/backgrounds/backgrounds/category

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.