Hoping for some help with URL rewrite

Sir there is a question i would like to post.
I have links on my website like:
But I want it to display it in my url like:
Can i get the code of url_write to be written in .htaccess file. I have rea your article regarding url rewriting but I’m unable to apply it. Also there are many other different links of this type with different parameters being pased in url. Do I have to rewrite all of them or there is any general code which could do the job for me.
Thanks in advance :smile:


RewriteEngine On
RewriteBase /folder1/
RewriteRule ^index\.php$ - [L]
RewriteRule ^(\d+)/ /folder1/index.php?qid=$1 [L]

sry but its not working. do i need to start my server. And is there any way to generalize it. Right now you provided it for folder1. do i need to change it every time

That code will work if you have a folder with name “folder1”, that have index.php and need to use

/folder1/NUMERIC_ID/ instead of /folder1/index.php?qid=NUMERIC_ID

This .htaccess only apply to folder1.

If you have a parrent folder with different URL rewrite, you need to create .htacess to handle that. Nothing will get auto generated, you will need to write rewrite rules, it is not that complex unless you need to make complex urls structure.

Its not working. Kindly visit to:
I have rewritten the .htaccess file but the url is still the same as mentioned above. It has not changed to:

Post content of your .htaccess file.

RewriteEngine On
RewriteBase /Aptitude/Discussion/
RewriteRule ^index.php$ - [L]
RewriteRule ^(\d+)/ /Aptitude/Discussion/index.php?qid=$1 [L]

one more thing, if I have a url like
I would like it to appear as
Then what should be the content of the .htaccess file. Kindly provide the code for it.

.htaccess Looks good. On which folder you put .htaccess ?

First lets get the ID part working, then category. Are you sure you named .htaccess correctly ? If any spelling mistake in file name, it won’t work.

EDIT: Look like godaddy cpanel hosting, so mod_rewrite must be enabled.

so what all i need to do now??? yes, the hosting is of godaddy and they havnt given the access of .htaccess file, I have made one for my own use and placed it in public_html file.

Upload .htaccess to /Aptitude/Discussion/ folder. Same folder where index.php is present.


FIrst, I loathe the inappropriate use of a trailing slash for anything other than a folder/directory. That causes relative link problems which you just don’t need.

Second, I’m not a fan of RewriteBase directives, either, as they take over (and change) links when least expected.

Instead, I prefer to put as much of my mod_rewrite in the DocumentRoot and reserve subdirectory mod_rewrite directives to .htaccess in the directories IF they’re specific to that directory.

That means that Host’s code needs changed slightly (he does get a kudos for his code) to:

# .htaccess in the DocumentRoot RewriteEngine on RewriteRule ^Aptitude/Discussion/([0-9]+)$ Aptitude/Discussion/index.php?qid=$1 [L]

That allows you to extend your mod_rewrite for Aptitude/General (except that you MUST use the same capitalization … unless you have server access to implement RewriteMap directives) to:

# ... continued from above RewriteRule ^Aptitude/General/([a-z]+)$ Aptitude/General/index.php?category=$1 [L]

See how easy that is?

You might benefit from reading the mod_rewrite tutorial linked in my signature (hmmm, no signatures any more ;( - https://datakoncepts.com/SEO) as it contains explanations and sample code. It’s helped may members and should help you, too.



1 Like

@dklynn thanks for the code. I read about it. It seems good but the url hav’nt still changed. I have a shared hosting and I cant find my .htaccess file in my public_html folder. Can this be a problem too?? I made my own .htaccess file and placed in public_html folder but it hasnt worked out. Now what can be the problem?? Is the hosting that is creating problem?


No problem. I used to be here all day every day (or so it seemed) helping members.

The URLs are NOT supposed to change. You want to use the “new format” URL but serve the “old format” (which can be served, the “new format” cannot). If you REALLY want to show the redirection, use an R=301 flag.

Shared hosting is not a problem as the server’s configuration is what determines what the filename of the “.htaccess” file is and whether or not you’re allowed to use this Apache feature. Earlier, I saw that someone was using GoDaddy as their host and they used to PROHIBIT clients from using .htaccess - if this is your case, go find a good host to use rather than a registrar.

public_html is the DocumentRoot for the “main domain” but can be above the DocumentRoot for Addon Domains. I suspect that this is the correct place for you. Just be sure that you’ve uploaded the .htaccess file in ASCII mode.



I cant buy a new hosting rt now. Is there any other way of url rewriting apart from .htaccess file??


There is always more than one way to do anything!

If I were unable to use .htaccess (and could not escape a bad host), I’d use my ErrorDocument to examine the requests which cannot be served (404’d) and use PHP’s power to redirect to the correct page. Off the top of my head, though, I believe you’ll have to display the actual file (i.e., index.php?qid=whatever or category=whatever. IMHO, that’s UGLY and you really need to look at finding a good host. There are plenty out there that will allow use of .htaccess and are probably less expensive (than GoDaddy?) but you get what you pay for (which is the reason I host with WebHostingBuzz.com).