1

I got the following url:

127.0.0.1/abc_123456/default/index/index/

Which should be rewritten to:

127.0.0.1/123456/index.php/default/index/index/

So remove abc_ and add index.php after it. Problem is that the digits are variable, but the abc_ isn't.

I had the following rule:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /abc_

RewriteRule ^abc_(.*)/(.*)$ /$1/index.php/$2

But that resulted in the url being rewritten to:

127.0.0.1/123456/default/index/index.php/index/

Seems like I'm almost there, but I can't figure it out.

Thanks in advance

3 Answers3

0

for example, if you need similar solution, when visited this url:

http://yoursite.com/subpage1/subpage2/?YOURSTRING=blabla

to redirected visitor to

http://yoursite.com/subpage1/subpage2/

then see link - http://stackoverflow.com/a/15680832/2215124

T.Todua
  • 53,146
  • 19
  • 236
  • 237
0

Try

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /abc_([0-9]+)/([^\ \?]+)  [NC]
RewriteRule ^ /%1/index.php/%2 [L]

EDIT

However, you are right about the other rule, that's the one giving the error; RewriteCond %{THE_REQUEST} !^[A-Z]+\ /abc_ RewriteRule ^(.*)$ /index.php/$1 That one is used to rewrite if the page does not contain the /abc_123456/

Add an extra condition to that rule as below

#if not abc_
RewriteCond %{THE_REQUEST} !^[A-Z]+\ /abc_  [NC]
#if not already index.php
RewriteCond %{REQUEST_URI} !^/index\.php$ [NC] 
RewriteRule ^(.*)$ /index.php/$1 [L]
Ulrich Palha
  • 9,411
  • 3
  • 25
  • 31
  • Gives me an internal server error. The condition seems alright, but the rule isn't. – Just someone Feb 07 '12 at 13:09
  • @user1194648 If you comment out the rules above, do you get an error if you access `127.0.0.1/123456/index.php/default/index/index/` directly. Do you have any other rules in your .htaccess? – Ulrich Palha Feb 07 '12 at 13:51
  • Requesting the url directly gives me the page as expected. However, you are right about the other rule, that's the one giving the error; RewriteCond %{THE_REQUEST} !^[A-Z]+\ /abc_ RewriteRule ^(.*)$ /index.php/$1 That one is used to rewrite if the page does not contain the /abc_123456/ – Just someone Feb 07 '12 at 14:02
  • Thank you for your effort. Your solution works too, though the above [anubhava] has my preferation as it is more neat. – Just someone Feb 07 '12 at 14:22
0

Use this simple rule:

RewriteRule ^abc_([0-9]+)/(.*)$ $1/index.php/$2 [L,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643