Domanda

I have been trying & searching alot but couldn't find any solution for i have tried many things in .htaccess

My website's Url mysite.org/torrents.php

To this mysite.org/Browse

This mysite.org/torrents.php?parent_cat=Movie

to this

mysite.org/Movie

This

mysite.org/account-details.php?id=737

to this

mysite.org/user/username

È stato utile?

Soluzione

Your links won't all work properly, i.e. the /user/username one won't work to an ID number, you could pass the username through then do a lookup based on the username, but htaccess won't know that username "tim" is id number "123"

This should work:

RewriteEngine On

RewriteRule "user/([0-9]*)"             account-details.php?id=$1
RewriteRule "category/([a-zA-Z0-9_-]*)" torrents.php?parent_cat=$1
RewriteRule "browse"                    torrents.php
RewriteRule ""                          torrents.php

With that I've separated out the categories into a subfolder called 'category' this makes it far easier to allow any category name you want.

For the regular expression matches in the RewriteRules theres an excellent free program called 'Expresso' that will help you build up regular expressions and test them against a list of values to see if they match, I'd recommend searching for it and getting a copy as it's very handy.

Also for the username part if you wanted to do username instead of user ID numbers, then swap:

RewriteRule "user/([0-9]*)" account-details.php?id=$1

to this:

RewriteRule "user/([a-zA-Z0-9_-]*)" account-details.php?username=$1

Altri suggerimenti

Try using this. it is a htaccess generator. If this doesn't work you will need to check you php.ini settings to see if it allows this type of link.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top