Rewrite problem

how can i rewrite a parameter only using rewrite engine??

example:
client: domain.com/news-hu.html
server: domain.com/news.php?page=news&lang=hu
client: domain.com/forum-hu.html
server: domain.com/forum.php?page=forum&lang=hu … etc.

how to change the parameter without changing the filename?

4example:
current page is: domain.com/news-hu.html

i click the slovak language ikon - with url domain.com/slovak.html - and need to change the url to domain.com/news-sk.html, without to changing the filename? i need capture current filename… or???

my current .htacces file


RewriteEngine On

RewriteRule hungarian.html$ main.php?lang=hu [L] 
RewriteRule slovak.html$ main.php?lang=sk [L] 

RewriteRule ^news-(.*)\\.html$ news.php?page=news&lang=$1 [L] 
RewriteRule ^gallery-(.*)\\.html$ gallery.php?page=news&lang=$1 [L] 
RewriteRule ^contacts-(.*)\\.html$ continfo.php?page=contacts&lang=$1 [L] 
RewriteRule ^forum-(.*)\\.html$ forum.php?page=forum&lang=$1 [L] 
RewriteRule ^impressum-(.*)\\.html$ main.php?page=impressum&lang=$1 [L] 

Excuse me 4 my english, but i am a beginner…

jope,

First, Welcome to SitePoint’s Apache forum!

Second, your English is far better than my … well, just about any other human language.

Although your basic request seems to be pretty straightforward and your code okay (it can be simplified, though), I’m concerned about your request to redirect the language URI to something Apache can not determine (the page type).

Of course, my basic ranting and raving about the use of lazy regex, the dreaded :kaioken: EVERYTHING :kaioken: atom, to match anything, everything, nothing and just plain garbage. PLEASE, for your own sake, learn some real regex - it’ll save you a lot of problems.

RewriteEngine On

RewriteRule hungarian.html$ main.php?lang=hu [L] 
RewriteRule slovak.html$ main.php?lang=sk [L] 

RewriteRule ^news-(.*)\\.html$ news.php?page=news&lang=$1 [L] 
RewriteRule ^gallery-(.*)\\.html$ gallery.php?page=news&lang=$1 [L] 
RewriteRule ^contacts-(.*)\\.html$ continfo.php?page=contacts&lang=$1 [L] 
RewriteRule ^forum-(.*)\\.html$ forum.php?page=forum&lang=$1 [L] 
RewriteRule ^impressum-(.*)\\.html$ main.php?page=impressum&lang=$1 [L] 

RewriteEngine on
RewriteRule hungarian.html$ main.php?lang=hu [L] 
RewriteRule slovak.html$ main.php?lang=sk [L] 

RewriteRule ^(news|gallery|contacts|forum|impressum)-(hu|sk)\\.html$ $1.php?page=$1&lang=$2[L]
# Note, this would require that you rename continfo.php
# to contacts.php and main.php to impressum.php
# (or provide a redirect to main after this RewriteRule).

Using regex, you can easily group similar redirects into a single statement. Since you KNOW that you will only have news, gallery, contacts, forum and impressum in the first atom and, presumably, the only languages are hu and sk, specifying these will eliminate NASTY problems when garbage is requested.

Regards,

DK

Thanx for your quick reply!
i have another question/problem :confused:

.htacces


RewriteEngine On

#Directory style
RewriteRule ^articles/(.*)/(.*)/(.*).html$ showarticle.php?lang=$1artid=$2 [L]


The third parameter is article title retrieved from database. It works, fine, but, it’s a problem.

example:
client: domain.com/articles/en/45784/install_winxp.html
server: showarticle.php?lang=en&artid=45784

The problem: Images are not displayed, css and Js are not included, because the path is,
example:

and images ar in folders: images, ikons,
styles in: css
javascripts in: js etc.

Any idea?

Thanx a lot!

Hi jope!

That’s what I termed the “Missing Support Files” problem in my signature’s tutorial (and your answers are there about how to resolve it). Please read the tutorial so you can learn how to avoid using (.*) as it’s more trouble than it’s worth (lazy regex).

Regards,

DK

i have to read tutorials at datakoncepts.com/seo but i can’t find the answer …
my modified .htacces is:


RewriteEngine On

#Directory style

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^articles/([A-Za-z]+)/([0-9]+)/?$ showarticle.php?lang=$1artid=$2 [L]

the problem is same…
images, css, javasripts, etc. are not loaded… :(:frowning:

jope,

You didn’t see the Relative Links Are Missing! section? Oh, well, because your showarticle script is told that it’s in the third or fourth subdirectory level, you MUST tell the script itself where it’s located ( <base href=“http://example.com/showarticle.php” /> ). This must be done WITHIN the script’s <head> block. Alternatively, you must use absolute URLs for all your support files and internal links.

Regards,

DK

…after this, the url is modified to domain.com/showarticle

:frowning:

my working htacces is:


RewriteEngine On
RewriteBase /

RewriteRule ^art/(.*)/(.*)/(.*)\\.html$ showarticle.php?artid=$2&lang=$1&lap=1 [NC]
RewriteRule ^art/(.*)/(.*)/img/(.*)$ http://%{HTTP_HOST}/img/$3 [NC]

thanx for tips and help :wink:

JOPE

jope,

Of course it does! Why did you make the redirection absolute rather than the links in the script as I said above (as the less-than-optimum solution - I had given you the <base> tag to begin with). In addition to that, you MUST use a Last flag to terminate a mod_rewrite block statement ELSE it’ll be ANDed with the next block statement! PLEASE read the tutorial linked in my signature - it’s ALL there!

Regards,

DK