user2109099 user2109099 - 1 month ago 7
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 http://example.org/newsarticles.php?pagenumber=3

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 http://example.org/de/newsarticles.php?pagenumber=3

I have tried the following, but it didnt work.

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

Answer

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]