I have a problem with Change url Script onarcade .
the code is
$categoryurl = $siteurl."/category/".$categoryId."/".$categoryId;
and in the .htaccess file
RewriteRule ^category/([0-9]+)/([_A-Za-z0-9-]+)/?$ browse.php?c=$1 [L]
the url like this
http://games.myarabvideos.com/category/1/1
I want the url become
http://games.myarabvideos.com/categoryNAME/1/1
$categoryNAME Variable on php code
example:
$categoryNAME=games;
i try this
$categoryurl = $siteurl."/category/".$categoryNAME."/".$categoryId;
but my problem in .htaccess file What Changes ??
The rewriterule you wrote down does not seem to be related to you desired redirect.
For what you need (and what I can understand), just replace:
$categoryurl = $siteurl."/category/".$categoryId."/".$categoryId;
with:
$categoryurl = $siteurl."/category/".$categoryNAME."/".$categoryId;
and that's all, in my opinion. Now you have to redirect all old ID urls to the new ones, one by one with single 301 redirect (no regex) i.e:
redirect 301 /category/1/1 http://yoursite.com/category/nameof1
redirect 301 /category/2/2 http://yoursite.com/category/nameof2
redirect 301 /category/3/3 http://yoursite.com/category/nameof3
...
and so on. Hope this helps ;-)
Related
I am familiar with redirecting URLs that don't have file types at the end, but not with ones that have .php at the end.
The website I'm working on has hundreds of indexed pages on Google that have this at the beginning of the url: http://example.com/index.php? with more information trailing afterwards.
An example is: http://example.com/index.php?main_page=index&cPath=1_18
The new index of the website is http://example.com/index or http://example.com
If I put http://example.com/index.php as the URL to be redirected, will it also redirect all index.php? Or do I need to put http://example.com/index.php* as the URL to be redirected or http://example.com/index.php?*?
Thank you!
If the main script to be executed is index.php, then there is no point in redirecting a url to itself...
Aabout those GET parameters in the url, if index.php oesn't use them, then.... they will be useless, but... thats it XD
The point is: does everything work without redirecting? If so, why redirecting at all?
If there are 301 redirects, ... that will mean more request to the server, and for those clients with low bandwith it does make a difference.
BTW, take a look at: htaccessredirect
Try:
RedirectMatch 301 ^/index\.php$ /
(or)
RedirectMatch 301 ^/index\.php$ /index
The query string at the end will automatically get appended.
If you're using wordpress now, you're not going to be able to use the mod_alias directive like above. You'll need to use mod_rewrite and place these rules above the wordpress rules:
RewriteCond %{THE_REQUEST} \ /+index\.php
RewriteRule ^ / [L,R=301]
(or replace the / at the end with /index)
I have a new site for an existing domain.
I want to redirect the old URLs to the new site, but the simple way of:
Redirect 301 oldURL newURL
isn't working.
I was told that there's a problem with the fact that the old URL contains index.php in it,
and that I need a rewrite rule for it...
example for new/old URLs:
old: http://www.example.com/index.php?type=store&category=11&subcategory=15&item=67
new: http://www.example.com/64-white-
would appreciate help with the rule I need to insert to the HTACCESS
tnx ahead
Guy
There are several ways to create a permanent redirect in .htaccess:
RedirectPermanent /index.php?type=store&category=11&subcategory=15&item=67 http://www.example.com/64-white-
Redirect 301 /index.php?type=store&category=11&subcategory=15&item=67 http://www.example.com/64-white-
RedirectRule /index.php?type=store&category=11&subcategory=15&item=67 http://www.example.com/64-white- [L,R=301]
Although, since you are talking about redirecting from index.php I would advise you to consider doing the redirect in code.
for examlple, you can create an oldsite_redirects.php file like this:
<?php
$redir_maps = array(
'/index.php?type=store&category=11&subcategory=15&item=67' => '/64-white-'
);
if(in_array(#$_SERVER['REQUEST_URI'], array_keys($redir_maps))){
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$redir_maps[#$_SERVER['REQUEST_URI']]);
exit;
}
?>
And in the index.php file add the following line ABOVE all code and comments:
require_once('oldsite_redirects.php');
hope this helps.
To make a permanent redirect in the htaccess file, you can use RedirectPermanent:
RedirectPermanent /index.php?type=store&category=11&subcategory=15&item=67 http://www.example.com/64-white-
due to the url re-writing, I think it is not possible to use a regular expression.
I've searched the site and got far enough where I've been successful at rewriting to a clean URL. Just need a bit more help.
I have a page with a record that I have successfully rewritten to a clean URL like so:
domain/record.php?id=1685 > to > domain/record-Gavin-Rees-1685 using the below:
.htaccess file:
RewriteRule ^record-(.*)-(.*)$ /record.php?id=$2 [L]
This in my php file:
$temp=str_replace(' ','-', $record [record_name]);
$temp=str_replace('.','', $temp);
<a href='/record-". $temp ."-".$record[id]." '>
This works perfect. The problem is.
I cannot get it to rewrite the other way so if you go directly to:
/record.php?id=1685 it still exists. i tried > RewriteRule ^record.php?id=$ /record-(.*)-(.*)$ [R,L]
This isn't possible in the .htacces rewrite rules, because you couldn't define a general rule, which knows about your software internals. If you want to do this in your .htaccess file, you have to create a rule for every single id which would result in a very large and unhandy .htaccess file.
The better way to get an redirection for direct script calls is, to do the redirect in the php file itself and set the http status codes(i.e. 301 - permanently moved).
The get the requested url, you could use $_SERVER['REQUEST_URI'] and check for /record.php at the beginning
OK, so I'm rewriting some page URLs for a custom PHP cart.
I've got the following rules:
RewriteRule ^category/([0-9]+)/([a-z-]+)$ /store.php?cat=$1 [L]
RewriteRule ^product/([0-9]+)/([a-z-]+)$ /product.php?id=$1 [L]
These will allow me to use a url structure like example.com/product/23/product-slug.
That part is working alright. I'm wondering what options I have for the other direction; redirecting requests for the OLD url to the NEW url. So for example, when someone goes to /product.php?id=2 I want to redirect to /products/2/slug.
Any idea how to get this done?
I tried a simple redirect, but would not work:
Redirect 301 ^/store\.php\?cat=16$ http://www.example.com/category/16/category-slug
Redirect only takes a url prefix, not a regex (e.g. /store.php or /store)
You need to try RedirectMatch:
RedirectMatch 301 ^/store\.php\?cat=16$ http://www.example.com/category/16/category-slug
Also, is it supposed to start with a /? I'm not sure (your RewriteRule entries above start with no slash, for example)
I solved this a different way: with a modification to the store.php file.
I looked at output from print_r($_SERVER) after pinging both the normal and rewritten urls. I found that $_SERVER['SCRIPT_URL'] contains "/store.php" when the normal url is hit and it contains my rewritten path when the rewritten url is hit.
This means I can do a simple test and redirect appropriately:
if ($_SERVER['SCRIPT_URL'] == "/store.php") {
// run some code that will generate the url
$rewrittenURL = generateURL();
// then add:
header("HTTP/1.0 301 Moved Permanently"); // tell spiders this is permanent
header("Location: $rewrittenURL");
}
On my site, users can add various URL's that need to be redirected.
For example; from this: domain.com/oldpage/36/
To this: domain.com/newpage/47/
They are added to the .htaccess like this:
Redirect 301 /oldpage/36/ /new-page/47/
But when accessing the old page they get this:
domain.com/newpage/47/?pid=36&pagename=oldpage
I'm pretty sure these rewrite rules are causing this predicament:
RewriteRule ([^.]+)/([0-9]+)/$ index.php?pid=$2&pagename=$1
RewriteRule ([^.]+)/([0-9]+)/([^.]+) index.php?pid=$2&pagename=$1&vars=$3
However, mod_rewrite stuff is not my strongpoint, so I have no idea how to fix it.
Any ideas ?
Adding a ? makes the Rewrite not add the query string to the url.
so this should work:
Redirect 301 /oldpage/36/ /new-page/47/?
As a precaution you could also add it to the end of:
RewriteRule ([^.]+)/([0-9]+)/$ index.php?pid=$2&pagename=$1?
RewriteRule ([^.]+)/([0-9]+)/([^.]+) index.php?pid=$2&pagename=$1&vars=$3?
But only if they are needed
Since you are already using mod_rewrite anyway, I suppose you should make your redirects using rewrites too
RewriteRule /oldpage/36/ /new-page/47/ [R=301]
This will "rewrite" the URL from old to new, and will redirect the browser to new url with status code 301. [R] directive means redirect, which also stops other rules from processing, hence the other rules will be handled only when the new request is sent from broswer with new url.