Home Set URL subdirectory in a GET element
Reply: 1

Set URL subdirectory in a GET element

swiftUser
1#
swiftUser Published in 2017-11-11 21:49:11Z

I have following directory on my Server:

Document Root
|
|- index.php 
|
|- /wiki
|    |
|    |-index.php
|    |
|    |-home.md
|    | 
|    |-foo.md
|    |
|    |-folder
|    |   |
|    |   |- foo.md

... and so on

I would like rewrite the ULR for the Wiki path. For example:

http://DOMAIN.tld/wiki/foo

Should be server side

http://DOMAIN.tld/wiki/?page=foo

and

http://DOMAIN.tld/wiki/folder/foo

Should be server side

http://DOMAIN.tld/wiki/?page=folder/foo

My idea is, transform the subdirectories to a GET element. In PHP, I can split the directory by / and perform my evaluation (PHP). After the wikifolder could be endless subfolder.

I use Apache (Plesk as Webserver) and PHP 7.

I tried following code in .htaccess:

RewriteEngine on
RewriteRule ^/wiki/(.*) /wiki/?page=$1

and my PHP code for testing (/wiki/index.php)

echo 'Hello Wiki';    
echo $_GET['page'];

If I call http://DOMAIN.dtl/wikii got the wiki page. If I call http://DOMAIN.dtl/wiki/testI got the 404 ERROR.

My question is: where is my mistake. I'm very grateful for every hint.

Edit:

change my htaccess file to :

RewriteEngine on
RewriteRule ^wiki/(.*) wiki?page=$1

Now I got following error message (Browser Safari): ERROR: Too many redirections

starkeen
2#
starkeen Reply to 2017-11-12 02:55:53Z

You are getting rewrite loop error due to the identical url pattern and destination path sincr wiki/index.php?page= also matches the pattern ^wiki/(.*) . To fix this, you need to exclude the destination path :

 RewriteEngine on
 RewriteCond ℅{REQUEST_URI} !^/wiki/index.php$ 
 RewriteRule ^wiki/(.*) wiki?page=$1
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.372378 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO