3

I do have a question regarding htaccess. I am trying to do the following:

blabla.com/lala and blabla.com/lulu

lala and lulu are my variables (showing different content on both sites, but it is the same file (example.php).

So what I did in htaccess is:

RewriteRule ^([^&]+)$ example.php?type=$1

But when echoing GET[type] I just get the filename("example.php"). But I want it to show "lala" or "lulu".

It works when I do it like that:

RewriteRule ^blablabla/([^&]+)$ example.php?type=$1

But I just don't need "blablabla" :D

Thanks in advance :)

1
  • Using [L] is definitly what you need Commented Oct 30, 2012 at 20:27

3 Answers 3

3

But when echoing GET[type] I just get the filename("example.php"). But I want it to show "lala" or "lulu".

This is because rewrite rules loop until the URI going into the rewrite engine is the same one that comes out of the engine. Your regex ^([^&]+)$ is matching the target of your rule (example.php). So you either need conditions to check if the URI isn't already example.php or you check if the request points to a file or directory that doesn't exist:

RerwiteCond %{REQUEST_URI} !/example\.php
RewriteRule ^(.+)$ example.php?type=$1 [L,QSA]

or

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ example.php?type=$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

1 Comment

Hi,I tried "RewriteRule ^(.+)$ example.php?type=$1 [L,QSA]". It does work on example.php. But its destroying other pages on the page where I already used it. I already used the following on top of the htaccess: "RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !/$"
1

Try this?

RewriteRule ^([A-Za-z0-9-]+)/?$ example.php?type=$1 [NC,L]

2 Comments

Nope, A-Za-z0-9- would select example
Also URI's sent through rules in htaccess files have the leading slash stripped off
0
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

QSA for query string rewrite

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.