Rewrite question

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 4
Joined: 06 May 2014, 12:07

Rewrite question

06 May 2014, 12:31

Hi all,

New to URL rewritting so forgive if this has been addressed elsewhere...

I'm trying to rewrite a url which is a number of folders deep, i.e. http://www.site.com/resources/directory ... /john-doe/ and make it end up being http://www.site.com/john-doe..

I was hoping to make one rule for all the peoples pages so that I don't need to make a rule for each.

I tried something like this;

rewriterule ^/resources/directory/people/(.*)/?$ /$1/ [NC]

But no go.

I'm sure I'm misunderstanding or doing something wrong, so any help would be great!
Thanks in advance!
Brance

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Rewrite question

06 May 2014, 15:18

Hello,

Try using:

Code: Select all
RewriteEngine on
RewriteBase /

RerwriteRule ^resources/directory/people/([^/]+)/?$ /$1/ [NC,R=301,L]


Regards

User avatar
Posts: 4
Joined: 06 May 2014, 12:07

Re: Rewrite question

06 May 2014, 15:34

Unfortunately that doesn't work either, as I receive a 404 when typing in the URL www.site.com/personsname/ Of course it could be that the prior rules to remove the "index.php" and force all requests to go through the ExpressionEngine system first (someone else wrote/created that part) makes it fail... However I guess what I'm not getting is how if the rule needs to have the first pattern "/resources/directory/people/personsname" to match on in order to rewrite to www.site.com/personsname/ it would ever work simply typing www.site.com/personsname in the address bar...
Am I being dense???

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Rewrite question

06 May 2014, 16:18

Well,

At the beginning I didn't know what you needed, now I'm getting an idea. You needs a second rule to map the content for a new pretty URL:

Code: Select all
RewriteEngine on
RewriteBase /

RerwriteRule ^resources/directory/people/([^/]+)/?$ /$1/ [NC,R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RerwriteRule ^([^/]+)/?$ /resources/directory/people/$1/ [NC,L]


So in this case, it'd check all requests that are only /XYZ/, not longer, then it'll check if such file or directory is real and rewrite it.

Regards

User avatar
Posts: 4
Joined: 06 May 2014, 12:07

Re: Rewrite question

06 May 2014, 16:50

Thank you Andrew! And as I'm understanding more I'm not sure what I want to accomplish is going to even work given that there is already a RequestCond and rewriteRule sending the request via the index.php file of the CMS system (ExpressionEngine). There is no directory per se, at least I can't find one in the wwwroot relating to the actual URL that is presented. It must be creating that directory structure via index.php within EE...

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Rewrite question

06 May 2014, 17:13

Could you share those rules you have?

User avatar
Posts: 4
Joined: 06 May 2014, 12:07

Re: Rewrite question

06 May 2014, 17:36

Sure!
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/cms_system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Of course these are at the root htaccess file. I would attempt to put the rewrite rules in the folder for the resources/directory/people but those folders don't exist in the webroot, I believe they are dynamically created via the EE system.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Rewrite question

07 May 2014, 17:46

Well,

this is quite different from what I expected. Usually we fix these differently by collaborating with a CMS. For example, take a look at WP - http://www.helicontech.com/articles/tun ... mpression/. However, i'm not familiar with EE. If you could investigate and see what it can do in terms of customized URL structure.

Regards

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 4 guests