0

I have a page on my wordpresss with url /sca. I want all traffic from /sca/project_0 to direct to /sca?urn=project_0. I added a rule to my .htaccess file but it is not working. I don't think this a problem with mod_rewrite as permalinks are working. Here is my .htaccess file:

 # BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^sca/([^/]*)$ sca/urn=$1 
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

RewriteRule ^sca/* sca?urn=$1 [R=301,L] is partly working, only that I'm not getting any parameter, it is returning /sca/project_0 as /sca?urn=.

7
  • 1
    Note the sca vs src in your question.
    – birgire
    Commented Nov 20, 2015 at 14:53
  • i've corrected it but it's not the issue
    – Noor
    Commented Nov 20, 2015 at 15:08
  • You need to put it right after the RewriteBase line. The [L] flag for the other rules mean "last", Apache will ignore yours where it is at the moment. Commented Nov 20, 2015 at 15:16
  • not working,it says page not found
    – Noor
    Commented Nov 20, 2015 at 15:28
  • i've updated the new .htaccess file
    – Noor
    Commented Nov 20, 2015 at 15:30

2 Answers 2

1

If this address already gets traffic (from inbound links etc.) why don't you try a good old fashioned redirect like this:

Redirect 301 /sca/project_0 http://www.yourdomain.com/sca?urn=project_0

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Or use the 301 redirect in addition to your rewrite rule:

Redirect 301 /sca/project_0 http://www.yourdomain.com/sca?urn=project_0

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^sca/([^/]*)$ sca/urn=$1 
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Also note that WP is often deleting additional rewrite rules inside #Begin WordPress #End WordPress. And sometimes rewrite rules do not behave like they should in localhost.

3
  • i'ts not on a localhost
    – Noor
    Commented Nov 20, 2015 at 18:19
  • it's not working
    – Noor
    Commented Nov 20, 2015 at 18:19
  • RewriteRule ^sca/* sca?urn=$1[R=301,L] is partly working, only that i'm not getting any parameter, it is returning /sca/project_0 as /sca?urn=
    – Noor
    Commented Nov 20, 2015 at 18:25
0

Try:

 RewriteRule ^sca/([^/]*)$ sca\?urn=$1 
3
  • nopes, still not working
    – Noor
    Commented Nov 20, 2015 at 16:49
  • RewriteRule ^sca/* sca?urn=$1[R=301,L] is partly working, only that i'm not getting any parameter, it is returning /sca/project_0 as /sca?urn=
    – Noor
    Commented Nov 20, 2015 at 18:25
  • Add the flag [QSA] to pass parameters. I think that will do it. Commented Nov 21, 2015 at 3:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.