0

I have created Test folder in main directory having file test.php https://example.com/test/test.php?id=123&z=dnfjk after rewriting i want to create https://example.com/test/test/123/dnfjk

I have used following code htaccess file

RewriteEngine on
RewriteRule ^(.*).html$ https://example.com/$1 [R=301,L]
RewriteRule ^(.*).htm$  https://example.com/$1 [R=301,L]
RewriteRule ^(.*).php$  https://example.com//$1 [R=301,L]

But it shows 404 error

  • 1
    So you're not using the WordPress environment but a custom .php file? – kero May 31 '18 at 7:13
  • So you want a kind of an automatic url generator for your test paramters? That is hard to create. Search for human readable url wordpress or just get inspired by this direct post answer: wordpress.stackexchange.com/a/258214/141935 – Pete May 31 '18 at 7:28
0

Assuming this is completely outside of WordPress then... to rewrite /test/test/123/dnfjk to /test/test.php?id=123&z=dnfjk, then you could do something like the following in the /test/.htaccess file (not the WordPress .htaccess file in the document root):

Options -MultiViews

RewriteEngine On
RewriteRule ^test/(\d+)/([a-z]+)$ test.php?id=$1&z=$2 [L]

MultiViews needs to be disabled for this to work.

RewriteRule ^(.*).html$ https://example.com/$1 [R=301,L]
RewriteRule ^(.*).htm$  https://example.com/$1 [R=301,L]
RewriteRule ^(.*).php$  https://example.com//$1 [R=301,L]

These are external redirects (as opposed to internal rewrites) and don't seem to relate to your example at all?

Note that you change the URL in your application, you don't issue a redirect to do this. You would only need the redirect if the old URL (with URL parameters) had already been indexed and/or linked to by third parties.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.