2

I need some push with this, I have website that URL structure looks like this

domain.com/folder/index.php?name=asdasdAs2

How do I remove this part of the URL index.php?name= so it looks like this

domain.com/folder/asdasdAs2

The passed value (asdasdAs2) sometimes also contain these symbols ( . ) or ( - ) or ( _ ) so it will look like this (asd.asdAs2) or (asdasd_As2) or (asd-aSd-As2)

I've been trying with this code in my .htaccess file but it doesn't work.

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteRule ^/folder/(.*) /folder/index.php?name=$1

and this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>

and this one too

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)$     $1/index.php?name=$2 [L]

The last one does the job but only with alphanumeric word ex.(asdasdAs2) but not on (asd.asd) or (asd_asdas2)

0

1 Answer 1

2

With your shown samples please try following .htaccess rules file.

Please make sure to:

  • Keep your .htaccess file along with folder named folder.
  • Clear your browser cache before testing your URLs.
RewriteEngine ON
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/(folder)/index\.php\?name=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]

##Internal rewrite rules from here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ $1/index.php?name=$2 [QSA,L]
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, the problem is solved. My .htaccess file is inside the root folder of the website. although I didn't cleared the cache before testing it out. But as i remember it's working without deleting the cache too. I tried with your solution too and works perfect. Thank you again
@MichaelJinston, for your particular scenario its recommended to have it in this way IMHO. Cheers and Happy learning.

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.