user1411607
user1411607

Reputation:

.htaccess redirect all sub directories under sub directory

I want to redirect all sub directories under sub directory root/windows/ to root/windows/ct.php

File structure of site is like

root/windows/ct.php

Redirect these type of url

http://www.site.com/windows/games/ or http://www.site.com/windows/games
http://www.site.com/windows/software/ or http://www.site.com/windows/software

To

http://www.site.com/windows/ct.php?ct=games
http://www.site.com/windows/ct.php?ct=software

I am trying like this but it redirects all url to sub directory root/windows/ct.php

RewriteRule ^([^/]*)/ /Site/windows/?ct=$1 [L]
RewriteRule ^([^/windows]*)/ /Site/windows/?ct=$1 [L] // this one shows internal server error

Complete .htaccess code

Options +FollowSymlinks
RewriteEngine on

<IfModule mod_rewrite.c>
RewriteRule ^(error) - [L]
RewriteRule ^[^/]*/[^/]*/(.*\.html) /Site/error/400/ [L]
RewriteRule ^([^/]*)/(.*\.html) /Site/software/?link=$1&id=$2 [L]
RewriteRule ^([^/]*)/ /Site/windows/?ct=$1 [L]
RewriteRule ^sitemap\.xml$ sitemap.php [L]
RewriteRule ^rss/(.*?)\.xml$ rss/$1.php [L]
</IfModule>

ErrorDocument 400 /Site/error/400/

I do not know well about .htaccess please see and suggest any possible way to do it. Thanks.

Upvotes: 3

Views: 2574

Answers (1)

Prix
Prix

Reputation: 19528

Give this a try:

<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^windows/([^/]+)/?$ /windows/ct.php?ct=$1 [L]
</IfModule>

For your localhost use this one:

<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /Site/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^windows/([^/]+)/?$ windows/ct.php?ct=$1 [NC,L]
</IfModule>

Upvotes: 3

Related Questions