Wordpress custom listing page - .htaccess

I have WordPress site that has films and actor custom post types. Also I'm creating relationship with films and actors.
I have a page to list films that related to actor. On this page visitors can see in which films actor take role.
This pages URL is like this:
http://www.mywebpage.com/actors-films/?id=123456
id refers to the actor, with this id I'm doing a query and showing it on the page.
also this page supports pagination, this URL works too:
http://www.mywebpage.com/actors-films/page/2/?id=123456
actors-film page is a page that uses a custom template, this template determines the actor id and shows his films.
Every thing works fine, but I want to change the URL a little bit SEO friendly.
I have tried many URL formats
http://www.mywebpage.com/actors-films/jim-carrey
I don't know why but this URL redirects to actors page.
http://www.mywebpage.com/actors/jim-carrey
http://www.mywebpage.com/actors-films/123456-jim-carrey
I have tried to catch this kind of URL with .htaccess but no way to catch it, it always shows a 404 not found.
So, I need to do a rewrite with pagination support, can you please suggest me a way to do this?
edit : here is my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^actors-films/([0-9]*)\-([^/]*)$ ^actors-films/?id=$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Edit : I have realized that not rules works for me :
example :
http://www.mywebsite.com/tex shows a 404 with this rule : RewriteRule ^/tex /index.php [L]

Here is the solution, create a page named
add_filter('query_vars', 'ap_register_query_vars');
function ap_url_redirect_rules(){
add_rewrite_rule('actors-films/([^/]*)','index.php?pagename=artist-film-list&actor_slug=$matches[1]','top');
flush_rewrite_rules();
}
function ap_register_query_vars($query_vars){
$query_vars[]='actor_slug';
return $query_vars;
}
Now we can call the url http://mywebsite.com/actors-films/john-doe

Related

Mod_Rewrite for URL with multiple variables | .htaccess

I develop an e-shop site with products so for this proposal i made a product page for each of products with Mod_Rewrite for URL with the code above in my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/([a-zA-Z0-9_-]+)|([a-zA-Z0-9_-]+))$ ./product.php?name=$1 [L]
So when user clicks on the link www.example.com/Nike-Air goes to Nike-Air shoes page and etc.
What i would like to do is to add one parameter more in the url, let's say size
RewriteRule ^(.*/([a-zA-Z0-9_-]+)|([a-zA-Z0-9_-]+))$ ./product.php?name=$1&size=$2 [L]
but this parameter to not append in the url, still to displays www.example.com/Nike-Air
and also to be able to get the size data from $_GET method.
Is it possible?
Any ideas guys?

not found error in webmaster when redirection handled through .htaccess

I am trying to find answer for this for a long time.
I have created one site and i handle the not found page(404 pages) through .htaccess.
Everything works great but when i submitted to google webmaster for indexing (in fetch as google) it showing an error ( status = not found).
Does anyone know How to tell google to handle these pages (index these pages)
my .htaccess file is
ERRORDOCUMENT 404 /redirect.php
in my redirect.php file i take the necessary action.
like if URL is www.mysite.com/username then profile of that user is shown
Thank in advance
Google will never index 404 error pages.
You can use .htaccess with:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /redirect.php [L]
which redirected all links to pages that do not exist
if you use:
RewriteRule ^ /redirect.php [R=301,L]
the link change in the browser. But with [L] you can show your page without link change.

rewrite url and get variable

How can I get the second part of a url to be a variable, rewrite it, and provide a fancy URL.
So example www.mywebsite.com/AFL would rewrite to www.mywebsite.com/index.php?league=AFL but would still display as www.mywebsite.com/AFL.
I am using the same pages for multiple leagues. When a user signs up they establish a league name in the database and then on each page I look for the league variable to display the info.
I also have many different pages. So a user could go to www.mywebsite/AFL/schedule_teamdisplay.php?Team=ABC&Year=2014. This would rewrite to www.mywebsite.com/schedule_teamdisplay.php?league=ALF&Team=ABC&Year=2014.
The league will always be the second entry in the URL.
Thanks
You can put this code in your htaccess (which has to be in your root folder)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /index.php?league=$1 [L]
RewriteCond %{DOCUMENT_ROOT}/$2 -f
RewriteRule ^([^/]+)/([^/]+)$ /$2?league=$1 [L,QSA]

rewrite rule with .htaccess to mask url

My present url structure :
domain.com/items/view/5
domain.com/user/view/5
domain.com/user/edit/5
Now i don't want users to directly know the 'id' in the url, as they can directly fire a query from the address bar.
Hence i want to mask the url to :
domain.com
i.e. domain.com/anything will come as it is but the url will not change.
Thanks in advance.
Also note that i have already made .htaccess file with following code to remove 'index.php' from the url and that is working perfect.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
Can't be done. The only way to hide the id is to pass it outside the url - i.e. as POST data; but .htaccess doesn't have access to that, only the url.
Your code should instead handle the fact that users could enter the url directly and either act correctly or use a http-redirect header to send the user back to the main page.

Redirect conflicting and not redirecting the correct URL

Need your guidance. i am stuck with permanent redirection via .htaccess in WordPress. I Went through many post on SF but were not up to mark.
Scenario :
i have 2 domains
both domains host same content but on different URL like; old-domain/apple = new-domain/apl
Requisite :
every URL on Old-domain.com should be redirected to New-domain.Net; as i wish means, i will decide which URL from previous domain should redirect to which url on new domain. This should no way be automatically done. There may be chances that i can point two or more URL of old domain to a particular URL on new-domain.
if a particular page or URL etc whatever it may be, is not found on old-domain then it should be redirected to New-domain.
there are few URL that doesn't exist on old-domain any more. with SEO point of view, i would like to redirect them as well on new-domain.
4.
This is what i got closest to doing what i wish.
# 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]
**redirect 301 /apple http://newdomain.com/apl
redirect 301 /colour http://newdomain.com/color**
</IfModule>
# END WordPress
But this set of codes does not work proper with my blog. instead it start to redirect old-domain/wp-admin/edit/php automatically to new-domain/wp-admin/edit/php
Looking for :
i am looking for perfect codes that can help me doing this. just do a demonstration on how to proceed with some fictitious domain name n url, so that i can understand and do my domains.
Thanks

Resources