Routing issue CodeIgniter - php

i have link
http://www.raffaello-test.com/static/frontend/deutsch/mode-bilder/mode-herren-krawatten/gianni-versace-herren-krawatten.jpg
but i need to hide "/static/frontend" remove this part from URL and get get image from this URL
http://www.raffaello-test.com/deutsch/mode-bilder/mode-herren-krawatten/gianni-versace-herren-krawatten.jpg
i think it will be from .htaccess

One of the option is to create a symlink in the document root.
Second option is to use htaccess rewrite rule. Something like the following should work fine:
RewriteRule ^((deutsch|english)/.+/.+/.+\.(jpe?g|png|gif))$ /static/frontend/$1 [L]
If you have more languages just add them in first parenthesis, like (deutsch|english|russian).
Also note that It's not recommended to use rewriting in high load production for static content, better use symlinks

Related

How to create custom URL user friendly?

I have a very peculiar requirement, hopefully I can explain it without being too confusing. I created a page template where I list some state's city, let's say the URL is like this: http://www.example.com/states/?q=ohio
and i would like to do it like http://www.example.com/states/ohio/
i also used add_rewrite_rule but it's does not given me output that i want.
so how could i do fix ?
It's actually not PHP, it's apache using mod_rewrite. What happens is the person requests the link, http://www.example.com/states/ohio/ and then apache chops it up using a rewrite rule making it look like this, http://www.example.com/states/?q=ohio, to the server. You can find more here: Rewrite Guide
Web server side
Since you're running Apache, you can create a RewriteRule to rewrite the URI to something that the application understands but have vanity/pretty URIs to your endusers.
For example;
RewriteEngine On
#Rewrites a request like http://www.example.com/states/ohio/ to http://www.example.com/states/?q=ohio at application level
#Having the /? at the end makes the ending slash optional
RewriteRule ^states/([^\/]+)/?$ /states/?q=$1 [L]
Tested with http://htaccess.mwl.be/
Wordpress side
You can use add_rewrite_rule to rewrite the URLs as you desire
add_rewrite_rule('^states/([^\/]+)/?$', 'states/?q=ohio$matches[1]', 'top');
Otherwise, you'd have to manually modify each href element on an anchor tag (<a />) to point to /states/ohio/ instead of /states/?q=ohio.

Recursive redirection in htaccess URL rewriting (mod_rewrite in Apache)

In the root folder of my project there are several other folders I am calling "apps". The path to one of these apps is something like: /root_folder/myapp/...
There are actually a dozen apps like this. So I want my project to be using friendly URLs, and to achieve that I am using the apache module mod_rewrite.
I added the following rule to my .htaccess (that is in root_folder, just so you to know) RewriteRule ([^/]*)/(.*)?$ myDomain.com/$1/index.php?params=$2 [NC,L]
So an URL such as mydomain/myApp/param/value/param2/value would be translated to mydomain/myApp/index.php?params=value/param2/value
I performed some tests and saw it working until I added the $1 to refer to the app folder (have a look: the_path_to_my_root_folder_here/$1/index.php?params=$2)
The path to one of these apps is something like: `/root_folder/myapp/...**
It is generating an URL like: myDomain.com/myApp/index.php?params=index.php
Well I thought it would be a recursion issue. So it seems that Apache will try another redirection after the first is performed, and then it will generate an URL like that
I found this thread in Stack Overflow
The problem with the answer is that it`s assuming I know when to stop.
Do you know how to make this second redirection to stop?
I am trying the following rule now
RewriteRule myDomain.com/([A-Za-z0-9-]+)/(.*)$/ myDomain.com/$1/index.php?params=$2 [NC,L], but it's not working properly. It is only matching the regex, if I do not pass parameters after the app name. so when I try myDomain.com/user/ it works (not receiving parameters), and fails when I try myDomain.com/user/products/1000/, for example. Instead of rewriting/redirecting, it is trying to find a folder products inside user and etc
Try changing your rewrite rule to something that will match the input url but not your output url. Something like this:
RewriteRule ^([^\/]+)\/([a-z]+)\/(.+)$ /$1/index.php?params=$2/$3
Place this rule in DOCUMET_ROOT/.htaccess:
RewriteEngine On
RewriteRule ^([^/]+)/(.+)$ /$1/index.php?params=$2 [L,QSA]
Unable to understand what you mean by the_path_to_my_root_folder_here

Remove url segment

I am using the codeigniter Tank_auth library and I want to remove the "auth' part from all the urls.
http://mysite.dev/auth/login
to
http://mysite.dev/login
Use the routes configuration, add something similar to this to application/config/routes.php:
$route['login'] = 'auth/login';
Once you got this set up, you can make the webserver to redirect users from the old url like this:
RewriteRule ^auth/login http://%{SERVER_NAME}/login [L,R=302]
This one will redirect old url requests to the newly handled /login, you might want to handle https:// or subdirectories in later part of the rule.
The whole setup seems a little hackish, changing the generated urls seem to be a better idea.

PHP rewrite rule is not working for query string

I am writing the following rules in htaccess file to change the query string as directory structure
RewriteRule ^dashboard/([0-9]*)?$ dashboard.php?user_id=$1
is used to rewrite the url. It is working fine on
localhost/project/dashboard // (dashboard.php)
and all links are as
localhost/project/css/style.css
localhost/project/js/script.js
But When I append an id
localhost/project/dashboard/1 // (dashboard.php?user_id=1)
It changes all the links as
localhost/project/dashboard/css/style.css
localhost/project/dashboard/js/script.js
Why it is appending the dashboard to all links
How is the style.css referenced in your html file?
If you have it like this href="css/style.css", the HTML doesn't know you're rewriting, thinks /1 is a folder and will look in dashboard/css/style.css
Any system that uses url rewrite usually has to write all the path to the styles and scripts to avoid this. so you will have to reference your style like this
href="http://localhost/project/css/style.css"
if you have a production and development environment it will help you to have a variable like
if($SERVER['SERVER_NAME']=='localhost'){
$BASE_URL = "http://localhost/project/"
}else{
$BASE_URL = "http://mydomain.com/"
}
and put that before any call to css, scripts or images
;)
It's because you "tell him" to do that.
RewriteRule ^dashboard/([0-9]*)?$ dashboard.php?user_id=$1
// ^here you tell him to print that "dashboard"
Of course other links works - you don't even match them with that rule.
I found you something here, scroll down to the title "Strip Query Strings". There, it say you to do this:
RewriteCond %{QUERY_STRING} example=
RewriteRule (.*) http://www.domain.com/$1? [R=301]
Just, of course, change that url to your own.

using seo user friendly in php

this is the URL path I currently use:
/index.php?page=1&title=articles
I want to get the URL path as
/index/page-1/title-articles
using SEO user friendly URLs in PHP.
And how to get the value of the "title"? Any one can help me pls.
Check out the mod_rewrite module, and maybe for a good starting point, this tutorial on how to take advantage of it with PHP.
You need to ensure two things:
your application prints out the new URLs properly, and
your webserver can understand that new URLs and rewrites them to your internal scheme or redirects them back to your application and your application does the rest.
The first part can be simply accomplished by using
echo ' … ';
instead of
echo ' … ';
The second part can be accomplished either with URl mapping features of your webserver (most webservers have a module like Apache’s mod_rewrite). With mod_rewrite, the following will do the rewrite:
RewriteEngine on
RewriteRule ^index/([^/-]+)-([^/]+)(.*) /index$3?$1=$2 [N,QSA]
RewriteRule ^index$ index.php [L]
The first rule will extract one parameter at a time and append it to the query. The second rule will finally rewrite the remaining /index URL path to /index.php.
I want to get the URL path as
/index/page-1/title-articles
Why? I’ve got two objections:
index is a no-information and I doubt that it belongs in the URI
page-1, as well as title-articles looks plain weird. Like with index, you should ask yourself whether this information belongs here. If it does, make clear that it’s the key of a key-value pair. Or remove it entirely.
Thus, I propose either:
/‹article›/1
or
/‹article›/page/1
or
/‹article›/page=1
or
/‹article›[1]
or
/articles/‹article›/page/1
Or any combination thereof. (In the above, ‹article› is a placeholder for the real title, the other words are literals).

Categories