user1373161
user1373161

Reputation:

.htaccess RewriteRule to get pretty links

I have URLs like:

1) http://www.example.com/?page=2
2) http://www.example.com/my-photos-folder?page=3

Here page number will increase sequentially (page=1, page=2, page=3 .....).

"my-photos-folder" Can be anything like "my-images-folder" or "Nice-photos" etc..

What i would like to get:

1) http://www.example.com/page/2
2) http://www.example.com/my-photos-folder/page/3 

My .htaccess has the following rules:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^page\/(.*)$ index.php?page=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L]
RewriteRule ^$ index.php?kohana_uri=$1 [QSA,PT,L]
RewriteRule ^index.php/(.*) $1 [QSA,R,L]
</IfModule>

Can any expert suggest me what rules i need to add so that my desired outcome will be achived. Thank you in advance.

Upvotes: 1

Views: 966

Answers (2)

user1373161
user1373161

Reputation:

@develroot

RewriteRule ^page\/(.*)$ index.php?page=$1 [L]  //This is working fine for homepage
RewriteRule ^(.*)\/page\/(.*)$ $1?page=$2 [L]   //this rule still not working on directory level.

The second one still have issue. Please consider the rules which are already there.[I have updated the question - added your first rule which work fine.]

Upvotes: 1

user562854
user562854

Reputation:

Add theese lines after the RewriteEngine On line:

RewriteRule ^page\/(.*)$ index.php?page=$1 [L]
RewriteRule ^(.*)\/page\/(.*)$ $1?page=$2 [L]

Upvotes: 1

Related Questions