Welcome Guest, Not a member yet? Register   Sign In
routes help - adds question mark.
#1

[eluser]dippy[/eluser]
i did a route on the following:

Code:
$route['services/search-engine-optimization'] = "services/seo";

but when i goto the url 'services/seo' it still works and doesn't redirect to services/search-engine-optimization but if i goto 'services/search-engine-optimization' it works great, thats what i need.

so i did a .htaccess redirect to try and fix it..

Code:
Redirect /services/seo http://www.mysite.com/services/search-engine-optimization


and now if someone goes to services/seo it redirects but adds a question mark. like so:
Code:
http://www.mysite.com/services/search-engine-optimization?/services/seo


how can i get 'services/seo' to redirect without it adding that question mark?? is there an option in CI?

please let me know as this is messing SEO up for the site and creating duplicate content.
#2

[eluser]dippy[/eluser]
here is my .htaccess file.

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php\?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|captcha|css|js|robots\.txt)
    RewriteRule ^(.*)$ /index.php\?/$1 [L]
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    Redirect /blog http://blog.mysite.com
    Redirect /services/seo http://www.mysite.com/services/search-engine-optimization
    Redirect /services/hosting  http://www.mysite.com/services/secure-web-hosting
    Redirect /services/design  http://www.mysite.com/services/web-design
    Redirect /services/email  http://www.mysite.com/services/complete-online-marketing
</IfModule>
#3

[eluser]Jeroen Brussich[/eluser]
Why are you using .htaccess to reroute your uri when CI has a built-in uri-router...
#4

[eluser]dippy[/eluser]
because the routes.php isn't redirecting it...

i can still goto services/seo and it show up...


am i doing something wrong?
#5

[eluser]Jeroen Brussich[/eluser]
Not being to big on .htaccess rewrite, I think your problem lies here:
Code:
RewriteRule ^(.*)$ /index.php\?/$1 [L]

What's that ? doing there?

All these lines below should also have [L] behind them, to tell .htaccess to stop going down the list. If you also want to change the uri, put [R,L]
Code:
Redirect /blog http://blog.mysite.com [L]
    Redirect /services/seo http://www.mysite.com/services/search-engine-optimization [L]
    Redirect /services/hosting  http://www.mysite.com/services/secure-web-hosting [L]
    Redirect /services/design  http://www.mysite.com/services/web-design [L]
    Redirect /services/email  http://www.mysite.com/services/complete-online-marketing [L]
update: changed <quote> to <code>
#6

[eluser]dippy[/eluser]
yeah me either.. i used that code from a post to take out the index.php

Thanks for the reply.. This is great info.

Do you know why the route isn't redirecting it? id rather not use the .htaccess file..

Thanks again for your help
#7

[eluser]Jeroen Brussich[/eluser]
I misunderstood your question the first time, that's why I brought up the URI-routing feature.

Modifying application/config/routes.php is cool if you want to modify CI's default behaviour towards example.com/class/function/id/, but can not be used to change the url in the address bar.

You will either need .htaccess for that (as you do now) or play around with redirect() (not recommended for your particular problem/feature/solution/...)
#8

[eluser]dippy[/eluser]
ok great.

ill take your advice from post #4.


thanks again!
#9

[eluser]dippy[/eluser]
if i take the '\?' out of the following line the url does not change.

Code:
RewriteRule ^(.*)$ /index.php\?/$1 [L]

all i get is the home page no matter what url i goto...

and if i use the [L] the .htaccess file and goto 'services/seo' it is redirecting me but still adding that to a query string like so
Code:
http://www.mysite.com/services/search-engine-optimization?/services/seo

BUT when i did take the '\?' out and tried to goto 'services/seo' the url went to the correct url and DID NOT add to the query string.. but the page stayed on the home page no matter what url i put in....

any thoughts? seems to be the .htaccess file thats adding the ?oldurl
#10

[eluser]Federico BaƱa[/eluser]
the question has no reason to be there, i think its used for poiting optional characters inside regular expressions but in your case it is escaped with the \ and thats why its being placed literally in the url.

just take that away.
now go to your config.php and look for a line like $config['uri_protocol'] = "AUTO" and change it to $config['uri_protocol'] = "REQUEST_URI".

i hope that helps.




Theme © iAndrew 2016 - Forum software by © MyBB