user2109099 user2109099 - 1 year ago 71
Apache Configuration Question

Using RewriteRule to make paths work

I am running a web site on Apache. For the sake of friendly urls I use .htaccess file with a RewriteRule that looks like this:

RewriteRule ^news/([^/]+) /newsarticles.php?pagenumber=$1 [NC,L]

This makes the link /news/3 lead to

But now I have a path for different language, how can I make it work the same way for that path using a separate .htaccess file located in that paths folder?

For example I want /de/news/3 lead to

I have tried the following, but it didnt work.

RewriteRule ^de/news/([^/]+) /de/newsarticles.php?pagenumber=$1 [NC,L]

Answer Source

You can use the same htaccess file. you don't need to have one explicitly in that directory. Try your rules this way.

Options -MultiViews
RewriteEngine on

#ignore real files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^de/news/([^/]+)/? /de/newsarticles.php?pagenumber=$1 [NC,L]
RewriteRule ^news/([^/]+)/? /newsarticles.php?pagenumber=$1 [NC,L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download