2

I would like to know if this final result can be achieved with some htaccess rules.

On the config folder. Where * is the page's name to show as folder.

/projectdir/config/?p=* or /projectdir/config/index.php?p=*
to /projectdir/config/*/

Example

/projectdir/config/?p=page1 => /projectdir/config/page1/
/projectdir/config/index.php?p=page1 => /projectdir/config/page1/

I tried the code posted in this question, but without results

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w\d~%.:_\-]+)$ index.php?p=$1 [NC]

Which basically: http://localhost/index.php?page=controller To

http://localhost/controller/

Whiteboard
  • 91
  • 10

1 Answers1

1

You can use this code in /project/config/.htaccess:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /project/config/

RewriteCond %{THE_REQUEST} /config/(?:index\.php)?\?p=([^\s&]+)&p2=([^\s&]+)\s [NC]
RewriteRule ^ %1/%2? [R=301,NE,L]

RewriteCond %{THE_REQUEST} /config/(?:index\.php)?\?p=([^\s&]+)\s [NC]
RewriteRule ^ %1? [R=301,NE,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?p=$1&p2=$2 [L,QSA]

RewriteRule ^([^/]+)/?$ index.php?p=$1 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thank you, but it doesn't work. With this code the result is this : `ip/project/config/?p=page1` => `ip/config/page1?p=page1` – Whiteboard Feb 08 '18 at 07:52
  • Ok now the rule works (in part), this is the result : `ip/project/config/?p=page1` => `ip/project/config/page1?p=page1` – Whiteboard Feb 08 '18 at 12:53
  • The result should be this `ip/project/config/?p=page1` => `ip/project/config/page1/` – Whiteboard Feb 08 '18 at 13:36
  • Hi, it's possible to modify the rule to handle a possible second parameter p2? If the parameter p2 is present `ip/project/config/?p=page1&p2=subpage1` => `ip/project/config/page1/subpage1`. I tried to modify the rule but not knowing well the grammar of the htaccess files i'm not succeeding in the intent. – Whiteboard Feb 09 '18 at 08:12
  • Hi, it's possible to edit this rules adding also this rule : `ip/project/config/?p=page1&param1=param1&param2=param2&param3=param3` => `ip/project/config/page1/param1/param2` (hiding the param3) , keeping the two rules already present? I tried to change the rules, but i think they conflict with each other. – Whiteboard Apr 05 '18 at 08:17
  • Hi! I have created another one :D https://stackoverflow.com/questions/50038133/htaccess-rewrite-url-two-variable-to-directory – Whiteboard Apr 26 '18 at 08:41