简体   繁体   中英

Problems with mod_rewrite dynamic URL

I've made my own blog on my domain and for displaying the articles I'm using a dynamic URL to display the article content on the page.

An example how it looks now: http://www.blog.madetocreate.nl/artikel.php?id=47

Now I've searched for a mod_rewrite method for days, but everything I tried fails. The service provider told me mod_rewrite is enabled and I only have to access it with a .htaccess file.

The file I have at this moment contains the following code:

RewriteEngine on
RewriteRule ^artikel/([^/]+)/?$ artikel.php?id=$1 [L]

I want to get the url to look like this:

http://www.blog.madetocreate.nl/artikel/47/title-of-the-post-here/

But so far I can't even get managed to get the first "artikel/47/"

Any idea on what I'm doing wrong?

Thanks!

The regex should look like the following:

^artikel/([0-9]+)/([\w-]*)$

Which gives you:

RewriteEngine on
RewriteRule ^artikel/([0-9]+)/([\w-]*)$ artikel.php?id=$1 [L]

([0-9]+) matches 1 or more number

([\\w-]*) matches 0 or more word character and - , meaning that you can have both artikel/47/ and artikel/47/title-of-the-post-here

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