Rafee
Rafee

Reputation: 4078

change url .htaccess php

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.

Upvotes: 1

Views: 358

Answers (3)

Zul
Zul

Reputation: 3608

What about this:

RewriteRule ^somethinghere1/somethinghere2/([^/\.]+).php/?$ page.php

Upvotes: 1

Ashraf
Ashraf

Reputation: 2632

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

Upvotes: 0

anubhava
anubhava

Reputation: 785316

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.

Upvotes: 0

Related Questions