1

I have been looking for a solution, but can't find one.

The problem is the following:

I have a directory on my website, for example domain.com/directory/. I made a custom CMS with custom URL's that are added after directory/, like for example domain.com/directory/example-page. I used htaccess to rewrite the URL of directory/post.php?url=xxx to directory/xxx

The problem is that it is not working, since I have an index.php file I want to keep using.

I fixed it by doing it like this:

RewriteRule ^directory/subdirectory/(.*)$ directory/post.php?url=$1 [NC,L] [QSA]

But I don't want to use the extra subdirectory in the URL.

So, how can I rewrite directory/post.php?url=xxx to directory/xxx while keeping directory/ working with index.php?

I know it sounds complicated, but I have been looking for a solution for days.

Thanks in advance!

2
  • Is your htaccess located in root? Commented Feb 6, 2017 at 18:22
  • @starkeen yes it is Commented Feb 6, 2017 at 18:25

2 Answers 2

1

You can use the following rule

RewriteEngine on

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

Comments

1

Not sure if I understand the issue correctly, but this should work;

RewriteRule    ^directory/?$    /index.php?url=test

3 Comments

Thanks for your suggestion, but the problem is I want to see my index.php page when visiting domain.com/directory/ as usual, but I also want to redirect directory/post.php?url=xxx to directory/xxx
@SenneVandenputte This should work, but you need to add it as an additional rule before the other one. This rule will pass onto index.php if there is nothing after directory/ and it needs a [L] flag to tell it to stop processing further rules. If there is anything after directory/, this rule will fail and the next will be processed.
@JonathanKuhn Thanks, but it's still not really what I'm looking for. I'll give exactly what I'm looking for. mydomain.com/guides/ contains a section of my website with guides and info on a specific topic. When visiting this URL, you are shown the index page, which is normal. There are also other files like guides/buying-guides and guides/training-guides, all rewritten to remove .php. Now, I have a post.php which uses parameters to be rewritten. So I need domain.com/guides/post.php?url=example to become domain.com/guides/example, while keeping my other files reachable as well.

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.