3

I try to add a rule to my htaccess to make it possible for me to route all article urls to be loaded by the same file.

Input: localhost/Project/article/my-test-article

Output: localhost/Project/article.php?id=my-test-article

I'm currently using this code... Which works:

#Enable backend url rewriting
Options +FollowSymLinks
RewriteEngine On
RewriteBase /Project/

#Route articles
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^artikkel/(.*)$ article.php?id=$1 [R]

Problem is, I don't want the user to be able to SEE the ?id=my-test-article! I don't want the url to change at all, really. I just need it to always load the same file all the time!

What would I have to do to accomplish that? I'm using WAMP.

Community
  • 1
  • 1
Ledii
  • 261
  • 1
  • 3
  • 13

1 Answers1

3

If you don't want the url to change in browser, Remove the R flag.

Options +FollowSymLinks
RewriteEngine On
RewriteBase /Project/

#Route articles
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^artikkel/(.*)$ article.php?id=$1 [NC,L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • Yes, I have tried that, and it KIND OF works... Problem then, is that my css files won't load from the same base. I use the same css file for the index.php and the article.php. For the index it can be loaded normally using "js/main.js" but for the articles I must use "../js/main.js" which is not very convinient. How to fix that? – Ledii Feb 13 '16 at 02:46
  • 1
    @Ledii to fix the css js and relative links , Add a base tage to the head of your document **** – Amit Verma Feb 13 '16 at 03:06
  • 1
    Thanks, that did it. Just had to refactor some code. – Ledii Feb 13 '16 at 03:23