1

I have a page name page.php and my url as localhost/mysite/page.php , now how can i change the url using .htaccess file to localhost/mysite/somethinghere1/somethinghere2/page.php

It tried using the below code but it doesn't work out.

<IfModule mod_rewrite.c>
# Enable Rewriting 
RewriteEngine On 

# Rewrite user URLs 
#   Input:  user/NAME/ 
#   Output: user.php?id=NAME 

RewriteRule ^somethinghere1/somethinghere2/.php? page.php

</IfModule>

how can i acheive this.

3 Answers 3

1

What about this:

RewriteRule ^somethinghere1/somethinghere2/([^/\.]+).php/?$ page.php
Sign up to request clarification or add additional context in comments.

3 Comments

I have edited the question and i also check your solution but it doesnt work out.
I got this one, but i need the localhost/mysite/page.php url to be changed to localhost/mysite/something1/something2/page.php and that what i am looking for.
@Rafee: so you need redirect localhost/mysite/page.php to localhost/mysite/something1/something2/page.php, you can do that using .htaccess to.
0

Use it like this:

RewriteRule ^(mysite/)somethinghere1/somethinghere2/(.*\.php)/?$ $1$2 [L,NC]

Also make sure this in .htaccess file in your DOCUMENT_ROOT directory.

Comments

0
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/page.php /page.php?first=$1&second=$2 [NC]

This is the basic code , you can play with it to fit your needs like the following edit :

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/([^/]+) /$3.php?first=$1&second=$2 [NC]

So x/y/z would be z.php?first=x&second=y

Comments

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.